Hello,
Are there any issues with MQX 4.0.2 with the TWR-K60D100M when using SPI2 DMA drivers? Based on the MQX examples I can successfully see data write, (SOUT <PTB22>), while doing a full duplex " ioctl (spifd, IO_IOCTL_SPI_READ_WRITE, &rw)". But RXFIFOs nor the memory location pointed to see the data on SIN, (PTB23).
Here are some of the lines of code I'm using in my project:
*******************************************************************************
/* Configure PINs */
PORTB_PCR20 = (0|PORT_PCR_MUX(2)); // Alt2 //CS
PORTB_PCR21 = (0|PORT_PCR_MUX(2)); // Alt2 //CLK
PORTB_PCR22 = (0|PORT_PCR_MUX(2)); // Alt2 //SOUT
PORTB_PCR23 = (0|PORT_PCR_MUX(2)|PORT_PCR_IRQC(3)); // Alt2 //SIN //DMA both edges ?
/* Open the SPI driver */
spifd = fopen (TEST_CHANNEL, NULL); // #define TEST_CHANNEL "spi2:"
//baud, clock mode, endian, transfer mode are from the MQX example.
/* Test simultaneous write and read */
memset (send_buffer, 0, sizeof (send_buffer));
memset (recv_buffer, 0, sizeof (recv_buffer));
send_buffer[0] = SPI_MEMORY_READ_DATA;
for (i = SPI_MEMORY_ADDRESS_BYTES; i != 0; i--)
{
send_buffer[i] = (SPI_MEMORY_ADDR1 >> ((SPI_MEMORY_ADDRESS_BYTES - i) << 3)) & 0xFF;
}
rw.BUFFER_LENGTH = 10;
rw.WRITE_BUFFER = (char_ptr)send_buffer;
rw.READ_BUFFER = (char_ptr)recv_buffer;
eips_user_dbprint0("IO_IOCTL_SPI_READ_WRITE ... ");
if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_READ_WRITE, &rw))
{
eips_user_dbprint0("OK\n\r");
}
else
{
eips_user_dbprint0("ERROR\n\r");
}
fflush (spifd);
***************************************************************************
I can see data from "rw.WRITE_BUFFER" on the wire and it matches.
I removed my slave dice for test purposes and looped back SOUT to SIN and still see nothing but all 0's in buffer rw.READ_BUFFER and SPI2_RXFRx registers. Is the data still stuck in the shift register?
With a break point after the ioctl above SPI register values are:
SPI2_MCR = 0x81fe0000
SPI2_TCR = 0x00fr40000
SPI2_SR = 0xc2000000
SPI2_RSER = 0x03030000
SPI2_POPR = 0x00
SPI2_RXFR0 to 3 = 0x00
Any ideas why RX FIFOs are not seeing any data in?
Thanks,
Mark
Solved! Go to Solution.
MQX was overiding my port PCR settings. Modify init_gpio.c \ _bsp_dspi_io_init : (See below) //* Configure GPIOB for DSPI2 peripheral function | * |
pctl = (PORT_MemMapPtr)PORTB_BASE_PTR;
pctl->PCR[20] = PORT_PCR_MUX(2); | //* DSPI2.PCS0 * | ||
pctl->PCR[21] = PORT_PCR_MUX(2); | //* DSPI2.SCK | * | |
pctl->PCR[22] = PORT_PCR_MUX(2); | //* DSPI2.SOUT * | ||
pctl->PCR[23] = PORT_PCR_MUX(2); | //* DSPI2.SIN | * | |
pctl = (PORT_MemMapPtr)PORTD_BASE_PTR; //Port D for CS1 | |||
pctl->PCR[15] = PORT_PCR_MUX(2); | //* DSPI2.PCS1 * |
//* Enable clock gate to DSPI2 module * | |
sim->SCGC3 |= SIM_SCGC3_SPI2_MASK; |
Mark
MQX was overiding my port PCR settings. Modify init_gpio.c \ _bsp_dspi_io_init : (See below) //* Configure GPIOB for DSPI2 peripheral function | * |
pctl = (PORT_MemMapPtr)PORTB_BASE_PTR;
pctl->PCR[20] = PORT_PCR_MUX(2); | //* DSPI2.PCS0 * | ||
pctl->PCR[21] = PORT_PCR_MUX(2); | //* DSPI2.SCK | * | |
pctl->PCR[22] = PORT_PCR_MUX(2); | //* DSPI2.SOUT * | ||
pctl->PCR[23] = PORT_PCR_MUX(2); | //* DSPI2.SIN | * | |
pctl = (PORT_MemMapPtr)PORTD_BASE_PTR; //Port D for CS1 | |||
pctl->PCR[15] = PORT_PCR_MUX(2); | //* DSPI2.PCS1 * |
//* Enable clock gate to DSPI2 module * | |
sim->SCGC3 |= SIM_SCGC3_SPI2_MASK; |
Mark
Hi Mark,
Please check the below threads and let me know if this helps,
Using MQX on a Kinetis K60 how do I change the SPI chip select?
Can somebody point me to exact changes to SPI (MQX) driver from 3.8.1 to 4.1.1 ?
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Sol,
Thanks for the response.
Just so I understand this correctly; Do Not use MQX( 4.x.x) - DMA with SPI2 drivers on older devices including the K60DN512?
I'm not having any problems with CS. The SPI2_RXFRx FIFOs are not receiving data.
Thanks,
Mark