I’m a bit confused what’s going on with the SPI on the i.MX6. Using the SPI driver from the Freescale SDK I tried to send 10 bytes from the master to the slave.
I just build up a test scenario where the master sends the 10 bytes and with a logic analyzer the MOSI is checked.
Sending data is 0xA0 to 0xA9 and the result in the logic analyzer is:
0xA1 0xA0 0xA7 0xA6 0xA5 0xA4 0x00 0x00 0xA9 0xA8
So in that case the 0xA3 0xA2 at the beginning are missing.
As I send a number of bytes which is dividable by 4, there is no problem.
I can expect that if the number of bytes is not dividable by 4 the last bytes are filled up. But as I can see there are 2 byes missing in the first 4 byte block.
It’s not as easy to explain the problem, so if there are any questions about this scenario….
Thanks for any hints.
已解决! 转到解答。
Hi,
I have not checked if that is something that can be changed in the module configuration but to overcome that, I created the below function that sorts the data so the ECSPI module sends it correctly.
u8 __attribute__ ((aligned(4))) g_spi_bcm89501_tx_buf[SPI_BCM_XFER_SZ];
u8 __attribute__ ((aligned(4))) g_spi_bcm89501_rx_buf[SPI_BCM_XFER_SZ];
int spi_XXX_xfer(unsigned char * u8ptrTx,unsigned char * u8ptrRx, int length)
{
int i;
int byteiterations, currentiteration;
unsigned char * u8ptrStartTx = u8ptrTx;
unsigned char * u8ptrStartRx = u8ptrRx;
int ByteOffset;
int nbytesoffset;
ByteOffset = length % 4;
nbytesoffset = 4 - ByteOffset;
if(ByteOffset == 0)
{
nbytesoffset = 0;
}
/*Get remaining of data*/
if(u8ptrTx != NULL)
{
u8ptrTx = u8ptrTx + ByteOffset;
currentiteration = 1;
byteiterations = length/4;
while( currentiteration <=byteiterations)
{
i = 4 * currentiteration++;
g_spi_bcm89501_tx_buf[i + 3] = *u8ptrTx++;
g_spi_bcm89501_tx_buf[i + 2] = *u8ptrTx++;
g_spi_bcm89501_tx_buf[i + 1] = *u8ptrTx++;
g_spi_bcm89501_tx_buf[i] = *u8ptrTx++;
}
/*point to beginnig of frame*/
u8ptrTx = u8ptrStartTx;
/*Copy the remainning bytes, they are the first ones*/
for(i = 3 ; i >= nbytesoffset ; i--)
{
g_spi_bcm89501_tx_buf[i - nbytesoffset] = *u8ptrTx++;
}
}
/*Begin Transfer*/
imx_ecspi_xfer(&imx_spi_bcm89501, g_spi_bcm89501_tx_buf, g_spi_bcm89501_rx_buf, (length) * 8);
/*Copy data from spi driver*/
if(u8ptrRx != NULL)
{
u8ptrRx = u8ptrRx + ByteOffset;
currentiteration = 1;
byteiterations = length/4;
while( currentiteration <=byteiterations)
{
i = 4 * currentiteration++;
*u8ptrRx++ = g_spi_bcm89501_rx_buf[i + 3];
*u8ptrRx++ = g_spi_bcm89501_rx_buf[i + 2];
*u8ptrRx++ = g_spi_bcm89501_rx_buf[i + 1];
*u8ptrRx++ = g_spi_bcm89501_rx_buf[i];
}
/*point to beginnig of frame*/
u8ptrRx = u8ptrStartRx;
/*Copy the remainning bytes, they are the first ones*/
for(i = 3 ; i >= nbytesoffset ; i--)
{
*u8ptrRx++ = g_spi_bcm89501_rx_buf[i - nbytesoffset];
}
}
return 0;
}
I hope you find that useful.
/Alejandro