Part Number: DAC81416EVM
Hi Experts,
Good day.
Do you have a C or C++ code to set up the SPI communication with teensy 4.1 and DAC61416? The DAC should give me the voltages 5v, 6v, 7v, and 10v in each channel.
Keep safe.
Regards,
Josel
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: DAC81416EVM
Hi Experts,
Good day.
Do you have a C or C++ code to set up the SPI communication with teensy 4.1 and DAC61416? The DAC should give me the voltages 5v, 6v, 7v, and 10v in each channel.
Keep safe.
Regards,
Josel
Hi Joselito Go,
Can you refer similar request in below e2e with code example. I hope it may help you.
Hi Anbu,
I saw that post earlier. But have you checked if the code is okay to use?
It seems the problem didn't resolve.
Can you help provide a clean code that can readily use?
Keep safe.
Regards,
Josel
Hi,
we dont have generic C or C++ code for this device. Below is the code example for TIVA Energia sketch which can be easily modified.
#define NUM_BYTES 3 //Number of bytes in SPI frame //SPIClass tivacSPI0(0); // SSI0 //SPIClass tivacSPI1(1); // SSI1 //SPIClass tivacSPI2(2); // SSI2 //SPIClass tivacSPI3(3); // SSI3 on port F SPIClass tivacSPI3_Q(4); // SSI3 on port Q void setup() { uint8_t initTx0[NUM_BYTES], initTx1[NUM_BYTES], initTx2[NUM_BYTES], i; int8_t ret; uint8_t *initPtr; Serial.begin(9600); Serial.print("Starting DAC81416 Example"); //tivacSPI0.begin(); //tivacSPI1.begin(); //tivacSPI2.begin(); //tivacSPI3.begin(); tivacSPI3_Q.begin(); pinMode(PD_2, OUTPUT); // Configure PD2 as CLR digitalWrite(PD_2, HIGH); // set CLR HIGH by default //Range: +/- 20V initTx0[0] = 0x0A; initTx0[1] = 0xCC; initTx0[2] = 0xCC; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); //Range: +/- 20V initTx0[0] = 0x0B; initTx0[1] = 0xCC; initTx0[2] = 0xCC; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); //Range: +/- 20V initTx0[0] = 0x0C; initTx0[1] = 0xCC; initTx0[2] = 0xCC; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); //Range: +/- 20V initTx0[0] = 0x0D; initTx0[1] = 0xCC; initTx0[2] = 0xCC; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); //Power-up device initTx0[0] = 0x03; initTx0[1] = 0x0A; initTx0[2] = 0x84; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); //Power-up all channels initTx0[0] = 0x09; initTx0[1] = 0x00; initTx0[2] = 0x00; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); //Enable Broadcast for all Channels initTx0[0] = 0x05; initTx0[1] = 0xFF; initTx0[2] = 0xFF; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); //Write Code to all Channels initTx0[0] = 0x0F; initTx0[1] = 0xFF; initTx0[2] = 0xFF; initPtr = &initTx0[0]; ret = tivacSPI3_Q.DACtransfer((uint8_t*)initPtr, (uint8_t)NUM_BYTES); } void loop() { int8_t rv, ldacFlag = 0; int32_t sampleCount; uint8_t *txPtr; uint8_t spiTx0[NUM_BYTES]; //Write Mid-code spiTx0[0] = 0x10; spiTx0[1] = 0x7F; spiTx0[2] = 0xFF; txPtr = &spiTx0[0]; rv = tivacSPI3_Q.DACtransfer((uint8_t*)txPtr, (uint8_t)(NUM_BYTES)); delay(100); //Write Full-code spiTx0[0] = 0x10; spiTx0[1] = 0xFF; spiTx0[2] = 0xFF; txPtr = &spiTx0[0]; rv = tivacSPI3_Q.DACtransfer((uint8_t*)txPtr, (uint8_t)(NUM_BYTES)); delay(100); } //Addition to SPI.cpp int8_t SPIClass::DACtransfer(uint8_t* datapointer, uint8_t numBytes) { unsigned long rxtxData[MAX_BYTES]; if(numBytes > MAX_BYTES){ return -1; } if(datapointer == NULL){ return -1; } for(int byteCount=0; byteCount < numBytes; byteCount++){ rxtxData[byteCount] = datapointer[byteCount]; } if(SSIBitOrder == LSBFIRST) { return -1; } for(int byteCount=0; byteCount < numBytes; byteCount++){ ROM_SSIDataPut(SSIBASE, (uint8_t) rxtxData[byteCount]); } while(ROM_SSIBusy(SSIBASE)); return (int8_t) 0; }
Here the code example using broadcast mode to update all channels with same data. you can modify with your DAC_DATA.
In case, you need a generic setting for SPI on any processor. It's as follows:
Mode: Mode-1 (CPOL=0, CPHA=1)
Order: MSB First
CS Polarity: Active Low
Number of Bytes: 3
You can use GPIOs for LDAC and CLR, if needed.
Regards,
AK