Hello,
I am new to the Freescale K20 family and currently working with the FRDM-K20D50M board. I have written a SPI driver from scratch (ie not using ProcessorExpert) since I am using IAR for my IDE. It is a simple driver in that it only transmits data and doesn't care about what is received. I have the SPI configured as a Master but things don't seem to be working quite right. The driver uses interrupts (but not DMA) to transfer bytes to a slave. When I attempt to send a buffer I can see two issues:
I have double- and triple-checked the connections to make sure my pin configuration and signal test points are correct. Are there any ideas as to what is wrong with the driver? I have also enclosed a main() application that sends [0x01, 0x02, 0x03, 0x04, 0x05] about every 1s that illustrates the issue.
Feedback is greatly appreciated.
Regards
Original Attachment has been moved to: blink_rgb.cpp.txt.zip
Original Attachment has been moved to: LDSpi0.cpp.txt.zip
Original Attachment has been moved to: LDSpi0.h.txt.zip
解決済! 解決策の投稿を見る。
I found the problem!!!
On the FRDM-K20D50M board there is a jumper J17. When the pins are shunted it enables the accelerometer on the board (an makes the SPI MOSI signal undefined). On the top of my board the jumper was not shunted so it made sense that the accelerometer wasn't enabled. However, when I turned the board over there is actually a trace between the pins on J17. As a result the accelerometer was actually enabled. I had the trace cut so that J17 would behave in the way it was intended.
I have enclosed pictures of what I am talking about.
Thanks for everyone's help.
Regards,
Mehmood
I found the problem!!!
On the FRDM-K20D50M board there is a jumper J17. When the pins are shunted it enables the accelerometer on the board (an makes the SPI MOSI signal undefined). On the top of my board the jumper was not shunted so it made sense that the accelerometer wasn't enabled. However, when I turned the board over there is actually a trace between the pins on J17. As a result the accelerometer was actually enabled. I had the trace cut so that J17 would behave in the way it was intended.
I have enclosed pictures of what I am talking about.
Thanks for everyone's help.
Regards,
Mehmood
You an easily use Processor Expert with IAR too (Tutorial: IAR + FreeRTOS + Freedom Board | MCU on Eclipse).
Even if you are not planning to use it, it provides a lot of help to get a driver working.
If you use it, you get a working initialization of your registers, and then you can copy the code.
Hi Erich,
Thanks for your suggestion. I have good news and not good news:
The good news is that I was able to use Processor Expert to generate the SPI master code for me. The interbyte time was also reduced quite a bit and the clock is set to the exact value that I wanted. The bad news is that the behaviour is identical to my original code. In the attached screenshots you can see the SS and CLK signals behaving correctly. The other screenshot shows the correct data but no CLK and SS associated with it.
Regards,
Mehmood
that really looks strange (SPI data shifted without the clock signal).
I see that you have two different SPI bus in your screenshot?
I know you said that you checked the signals, but are you 200% sure you use the correct pin/signal.
Otherwise (I have not checked), maybe this is documented in the errata of the device?
Hi Mehmood,
Please check the clock frequency given to the SPI peripheral. The clock module needs to be initialized separately.
An then you can calculate the baudrate according to the SCK baud rate = (fsys/PBR) x [(1+DBR)/BR] where fsys is the peripheral clock.
Hi Nasreen,
Thanks for your suggestions. If I understand correctly, are you recommending verifying the SPI_CTAR register settings? Once I check those settings I presume the other register settings look correct?
Best regards,
Mehmood