2014年3月6日木曜日

Raspberry Pi 12bit 1ch DA Module (Manual Mode with wiringPi)

Raspberry Pi 12bit 1ch DA Module (Manual Mode with wiringPi)

AD 8ch module has MCP4921.
You can use it easily, just put these functions on your main.c file or make header file and link these.
void setIOSimpleSPI(MCUGear *mcugear);
void write12bitDA(int spichan, int ratchPin, int data);

void setIOSimpleSPI(MCUGear *mcugear){
 //for AD 2ch, AD 8ch and multifunction module
 //1:MISO 13
 //2:MOSI 12
 //3:SCK  14
 //4:CE0  10
    mcugear->setWire(IO_13, IO_REG_IN_DIR, 0);
    mcugear->setWire(IO_12, IO_REG_OUT_DIR, 1);
    mcugear->setWire(IO_14, IO_REG_OUT_DIR, 2);
    mcugear->setWire(IO_10, IO_REG_OUT_DIR, 3);
 
}

void write12bitDA(int spichan, int ratchPin, int data){  //ratchPin must be same as setIODA()
 
 unsigned char spiBuff[2];
 
 digitalWrite(ratchPin,1); //for DA ratch
  
 spiBuff[0] = (0x30 + ((data>>8) & 0x0f));
 spiBuff[1] = (data& 0xff);
 digitalWrite(ratchPin,0); //for DA ratch
 digitalWrite(ratchPin,1); //for DA ratch
 
 //printf("data = %d : %x %x",data, spiBuff[0], spiBuff[1]);
 
 wiringPiSPIDataRW(spichan,spiBuff,2);
  
}

0 件のコメント:

コメントを投稿