Easy Embedded Programming: How to Program an I2C and SPI bus

发布人是

The fourth video explains how to program an I2C and SPI bus. These are necessary to communicate with external components on the same bus.

To demonstrate the SPI, the SCB component is also used but configured as SPI this time. The L6474 datasheet gives all the specifications to configure the bus. It is said that the SDI is sampled on the rising edges of the CK and the SDO is latched on the falling edges of the CK. In SPI specification that is translated CPHA = 1 and CPOL = 1. MSB must be first and it’s a standard Motorola protocol. After each byte transmission, the chip select must be rised high that is the case.

This configuration is entered in the GUI that pops up when clicking on the SPI component. The purpose of this exercise is to read the L6474 configuration register. It has the address 0x18 and a default value of 0x2E88. To get this value, we need to send a GetParam command with the binary value bx0011 1000 = 0x38. The protocol requires to send the GatParam command followed by 2 NOP functions to receive 2 bytes of data.


 Before writing code, pin out must be configured. Following arduino rules, the SPI pins are port 0, pins 0, 1, 2 and 3. The L6474 must also be reset, and the pin is on port 0 pin 5.


Using the SPI APIs generated by the PSOC, the program is again simple. After resetting the device, the SPI block is started. A function, setUpDefaultValuesL6474 is called to send the command GetParam at address 0x18 followed by 2 NOP functions. SPIM_SendCommandPacket is called with the buffer {0x38, 0x00, 0x00} and put in an array to be transferred thanks to the function SPIM_spiUartPutArray. As the number of bytes sent is equal to the number of bytes received, once the received buffer size is to this number, we know we received all the data. This data is then extracted and the buffer is cleared.
 

A great advantage of arduino shields is the easy access to all the pins. A logic analyzer can sniff exchange packets and save a lot of time in the debug phase. As shown below, 0x38 was sent, and two packets, respectively, 0x2E and 0x88 were received. . The SPI bus works as expected and the PSOC communicated with the motor driver L6474.

 



最新视频

抱歉,您所选择的筛选条件未返回任何结果。

请仔细阅读我们近期更改的隐私政策。当按下确认键时,您已了解并同意艾睿电子的隐私政策和用户协议。

本网站需使用cookies以改善用户您的体验并进一步改进我们的网站。此处阅读了解关于网站cookies的使用以及如何禁用cookies。网页cookies和追踪功能或許用于市场分析。当您按下同意按钮,您已经了解并同意在您的设备上接受cookies,并给予网站追踪权限。更多关于如何取消网站cookies及追踪的信息,请点击下方“阅读更多”。尽管同意启用cookies追踪与否取决用户意愿,取消网页cookies及追踪可能导致网站运作或显示异常,亦或导致相关推荐广告减少。

我们尊重您的隐私。请在此阅读我们的隐私政策。