I'm trying to use the driver in qspi.cpp to control the QSPI on the PK70. The part I'm communicating with is an Analog Devices AD5362 D/A chip, and requires 24-bit transfers. However, when I try to send data using QSPIStart, I get strange behaviour.
For example, if I want to write a single (24-bit) word to the AD5362, I call the code like this:
QSPIStart(pTxBuf, pRxBuf, 3, pSema);
According to the documentation, the third parameter (3) is the number of bytes to transfer. However, when I look at my logic analyzer, I see the CS go low, a burst of 16 clock cycles along with the first 16 bits of data, then a long pause, then the CS goes high. If I lie and pass 4 instead, it works - I get the burst of 16 bits, then a delay, and then the final burst of 8.
This also works if I write more data. If I want to send two 24-bit words, I must tell it 8 bytes, for three words, 12 bytes. In other words, N*(3 + 1), where N is the number of words, 3 is the number of bytes per word, and the 1 is the fudge.
Here is the part of QSPI_Isr() in qspi.cpp that I think is faulty - the comments are mine:
Code: Select all
else if((QSPIrec.BitsPerQueue > 16) && (QSPIrec.BitsPerQueue < 25))
{
// Not sure what this is all about...
if(QSPIrec.QSPI_SizeLeft > 32)
{
QSPIrec.QSPI_SizeLeft -= 32;
}
else
{
regWordsToWrite = (QSPIrec.QSPI_SizeLeft / 2);
if(regWordsToWrite)
{
sim_qspi.qwr &= ~(0x0F00);
sim_qspi.qwr |= ((regWordsToWrite-1) << 8);
}
QSPIrec.QSPI_SizeLeft = 0;
}
if(Txbuf)
{
sim_qspi.qar = 0x0;
for(i = 0; i < regWordsToWrite; i+=2)
{
// Really should have another byte, right?
sim_qspi.qdr = (*(PDWORD)Txbuf >> 8);
sim_qspi.qdr = (*(PDWORD)Txbuf & 0xFF);
Txbuf += 4;
}
}
if(Rxbuf)
{
sim_qspi.qar = 0x10;
for( i=0; i < regLastWordsToWrite; i+=2)
{
// Ditto, another byte?
*(PDWORD)Rxbuf = (sim_qspi.qdr << 8);
*(PDWORD)Rxbuf |= sim_qspi.qdr;
Rxbuf += 4;
}
}
}
This just looks wrong - or am I missing something?
Thanks,
-Bob