04-29-2013 05:12 PM
I'm using LIFA to control the Arduino Uno for automated testing of an RF circuit card. Part of the test is programming the AD4108 PLL Freq synthesizer chip. I've attached the datasheet for reference(see timing diagram). I'm sending four 24 bit words via the SPI VIs included with LIFA. Using an oscilloscope everything looks good except that the SPI VIs use an active low chip select(CS). THis means the CS pin is normally high and data is shifted out as the CS is held low. The AD4108 uses a load enable(LE) meaning LE is normally low as the data is transmitted and then a pulse of the LE indicates the end of the transmission. How can I accomplish this with LIFA? I have been racking my brain trying to figure this out. Thanks in advance.
Solved! Go to Solution.
05-04-2013 11:24 AM
Hey VinnyOB,
I did this really quick based on your description so let me know if it doesn't work. In the LIFA Firmware replace the spi_sendReceive function with the following and re-deploy the new firmware to the target:
(new code is marked with //ADDED THIS LINE
)
void spi_sendReceive(unsigned char command[])
{
digitalWrite(spiCSPin, LOW); //ADDED THIS LINE
if(command[2] == 1) //Check to see if this is the first of a series of SPI packets
{
spiBytesSent = 0;
spiCSPin = command[3];
spiWordSize = command[4];
// Send First Packet's 8 Data Bytes
for(int i=0; i<command[5]; i++)
{
// If this is the start of a new word toggle CS LOW
if( (spiBytesSent == 0) || (spiBytesSent % spiWordSize == 0) )
{
digitalWrite(spiCSPin, LOW);
}
// Send SPI Byte
Serial.print(SPI.transfer(command[i+6]));
spiBytesSent++;
// If word is complete set CS High
if(spiBytesSent % spiWordSize == 0)
{
digitalWrite(spiCSPin, HIGH);
delay(1); //ADDED THIS LINE
digitalWrite(spiCSPin, LOW); //ADDED THIS LINE
}
}
}
else
{
// SPI Data Packet - Send SPI Bytes
for(int i=0; i<command[3]; i++)
{
// If this is the start of a new word toggle CS LOW
if( (spiBytesSent == 0) || (spiBytesSent % spiWordSize == 0) )
{
digitalWrite(spiCSPin, LOW);
}
// Send SPI Byte
Serial.write(SPI.transfer(command[i+4]));
spiBytesSent++;
// If word is complete set CS High
if(spiBytesSent % spiWordSize == 0)
{
digitalWrite(spiCSPin, HIGH);
delay(1); //ADDED THIS LINE
digitalWrite(spiCSPin, LOW); //ADDED THIS LINE
}
}
}
}
05-06-2013 10:41 AM
Sammy,
Thanks for your response. I will try your code once I get a chance. I actually got it working late last week by manually toggling a digital pin (non CS) in between each of the 4 24 bit words. It took some extra LabVIEW code so it is not as elegant as your solution but it is working. Thanks again.