I have the LPCXpresso54102 board and setting it as SPI slave. It is working upto 12MHz but beyond that I am facing data corruption. I want to configure it to max possible (22MHz). Any advise will be helpful.
We are using in DMA mode not in interrupt or polling mode. so it should work without any software changes.
Can you please provide an example code snippet of SPI1 as slave in DMA mode?
Hi Tarun Chaplot,
About the DMA SPI slave code, you can refer to our lpcopen code for LPC54102.
lpcxpresso IDE project:
IAR and MDK project:
http://www.nxp.com/assets/downloads/data/en/software/lpc5410x_xpresso54102_keil_iar_v3.03.000_16.zip
After you unzip it, you can find the code in folder: lpc5410x_xpresso54102_lpcxpresso_v3.03.000_16\xpresso_src\periph_spis_dma
If you want to use the SPI1, please modify the spis_dma.c
#define APP_SPI_CH LPC_SPI1//LPC_SPI0
#define APP_SPI_DMA_RXCH DMAREQ_SPI1_RX//DMAREQ_SPI0_RX
#define APP_SPI_DMA_TXCH DMAREQ_SPI1_TX//DMAREQ_SPI0_TX
Then use the SPI1 according pin:
/* SPI1 */
{1, 6, (IOCON_FUNC2 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)},/* SPI1_SCK */
{1, 7, (IOCON_FUNC2 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)},/* SPI1_MOSI */
{1, 14, (IOCON_FUNC4 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)},/* SPI1_MISO */
{1, 15, (IOCON_FUNC4 | IOCON_MODE_PULLDOWN | IOCON_DIGITAL_EN)},/* SPI1_SSEL0 */
Wish it helps you!
If you still have question, please let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Kerry
Did you get the chance to try my project?
Are you able to run SPI slaveupto 21 Mbps?
Hi Tarun Chaplot,
I already help you to modify the lpcopen code:periph_spi_sm_int, it now can work with 21Mhz, using the SPI FIFO.
The main problem of lpcopen can't reach higher than 12Mhz is:
1. The system clock should configure higher, if you just use 12Mhz, of couse, it can't reach higher than 12Mhz.
So, you can use PLL to get 96MHZ.
Modify points, in the board.h,
#define BOARD_MAINCLOCKRATE (96000000)
If you use different board, both master and slave SPI board should configure the system clock to 96MHZ.
2. Configure the SPI modoule clock base, the async APB clock should also higher than 12Mhz.
The lpcopen just use 12Mhz as the SPI source, so you can't generate higher than 12MH baudrate.
Please add this code in the main:
Chip_Clock_SetAsyncSysconClockSource(SYSCON_ASYNC_SYSPLLOUT);
Then build and test it in the lpcxpresso LPC54102 board, I can get 21Mhz SPI, and the data is correct, this is the test result and the SPI wave.
I also attached my test project for your reference.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Kerry
Yes I am using baud rate of 100 MHz in my project.
Also we did try the change you suggested.
I am not using FIFO. I am using DMA because I will need higher throughput in my application.
With regards to the screenshot you sent I can see that On Master Rx you have not received the data same is what sent on Slave Tx.
I am asking this because I am facing similar problem. From master to slave the data goes fine at 21 MHz. But from slave to master the data is not received correctly.
If you can send one example with DMA than it will be of great help. My project is at critical stage and this is stopping to proceed.
Really appreciate your quick and helpful response.
Thanks
Tarun
Hi Tarun Chaplot,
I got the root problem why the master can't receive the correct data from slave in 21MHZ.
It's still the clock problem, the logic analyzer tool sampling rate is not enough, the clock rate is measured wrong.
I check it with the oscilloscope again, the defined 21Mhz baud rate, actually , the output spi clock is 24Mhz.
As you know, the LPC54102, the maximum supported bit rate for SPI slave mode is 21Mbit/s.
But the core clock is 96Mhz, if you debug the code, you will find the SPI divier register is 3, the divider is 4.
Divider 4 will cause the SPI clock rate to : 96M/4=24Mhz.
So, it already exceed the maximum supported bit rate for SPI slave mode.
Then the core is 96Mhz, and it is the source for SPI module, then the slave spi max bit rate is : 96MHz/5=19.2Mhz.
So, I configure code:
#define LPCMASTERCLOCKRATE 19000000
It will set the divider register to 4(divider is 4+1=5), the debug data is:
Then I check the clock rate in the oscilloscope, it is 19.2Mhz, just as defined.
The terminal data is:
You can find, if the master clock is in the range of the slave maximum clock, the transfer data is correct.
If you meet the similar problem in the DMA SPI mode, so, please check your clock configuration like me. use the oscilloscope to check the spi rate, whether it is correct.
I don't have the direct DMA SPI code now, I need time to create and debug it. But tomorrow, I will on my Chinese New Year vocation, maybe the DMA SPI project creation will be in Feb.
So, if you don't mind, you can use my code which send you before at first, just modify the spi_sm_int.c, line79:
#define LPCMASTERCLOCKRATE 19000000
Choose the communication clock to 19Mhz.
If you still want to get the 21Mhz, you need to configure the master SPI module clock to 42MHZ, 63Mhz, 84Mhz.
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thanks a lot. This was very helpful.
I changed SPI clock to 21 MHz
#define LPCMASTERCLOCKRATE (21000000)
and main clock to 84 MHz
#define BOARD_MAINCLOCKRATE (84000000)
It works but at 21 MHz I still see some duplicate data.
Thanks a lot anyways.
Best Regards
Tarun
Hi Tarun Chaplot,
I have tried the 84Mhz core, and the SPI clock to 21Mhz, the FIFO code also works.
You can share your updated DMA code, I will help you to check it on my side.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
HI Tarun Chaplot,
I already get your project, when I have time, I will test it on my side, then tell you my test result ASAP.
Now, please wait patiently!
Thanks a lot for your understanding!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Kerry
Thanks for the project. But I have used the same project. I have used SPI0 as master and SPI1 as slave.
I can attach my master project here so can you check what mistake I am doing?
Thanks
Tarun
Hi Tarun Chaplot,
According to the datasheet, the maximum supported bit rate for SPI salve mode is 21Mbit/s LPC54102 .
So, 12Mhz must can work from the hardware side.
But because the bit rate is high, I suggest you take care of the software execution time, you should better use the interrupt instead of the polling code, and in the interrupt service code, please use the code as simple, short as possible.
Please simplify the code, then try again.
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------