We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to communicate NXP LPC2378 (ARM7 core) to some other devices via SPI (Serial Peripheral Interface) protocol.
So how to write a C code to communicate a particular device as a Slave with Master (ARM7 controller)?
Hello razakamal,
If you are not well familiar with the details of SPI communication, I recommend this tutorial by SparkFun - they also have tutorials on I2C bus and serial/UART.
The LPC2378 can perform as either a SPI master or slave, although usually the MCU is the SPI master and the external device is the SPI slave. LPC2378 has configurations for the 4 types of communication formats supported by SPI, allowing to set the clock polarity and data phase selections. You'll need to be sure to check the requirements of the external IC, to see if it needs a certain polarity and phase configuration, and then create the matching configuration on the MCU.
When the MCU is the SPI master, it will likely need to enable the external device's SPI interface by setting its slave select input pin. I would recommend simply using a general purpose digital output to drive the slave select to its required active or idle levels - these levels are defined in the device's data sheet. Some SPI slaves have very specific requirements for sending & receiving packets or frames. In this case, your software will need to provide the communication flow that meets these requirements.
Sample code is available at NXP lpcware.com site, at this link. The code is written for Keil's MCB2300 board, but can be adapted to other platforms. Embedded Artists also has very nice dev boards, and sample source code as well.
Final note: You might consider moving to a Cortex-M platform, which is the upgrade/replacement for ARM7 products. There are many improvements with Cortex-M, relating to CPU performance, interrupt efficiency, and general scalability. NXP's LPC1700 series would be a good place to start, and there is wide support on the 'net.
Enjoy!
-arw