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

Veröffentlicht von

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.

 



Neueste Videos

Leider hat Ihre Filterauswahl keine Ergebnisse zurückgegeben.

Aktuelles über Elektronikkomponenten­

Wir haben unsere Datenschutzbestimmungen aktualisiert. Bitte nehmen Sie sich einen Moment Zeit, diese Änderungen zu überprüfen. Mit einem Klick auf "Ich stimme zu", stimmen Sie den Datenschutz- und Nutzungsbedingungen von Arrow Electronics zu.

Wir verwenden Cookies, um den Anwendernutzen zu vergrößern und unsere Webseite zu optimieren. Mehr über Cookies und wie man sie abschaltet finden Sie hier. Cookies und tracking Technologien können für Marketingzwecke verwendet werden.
Durch Klicken von „RICHTLINIEN AKZEPTIEREN“ stimmen Sie der Verwendung von Cookies auf Ihrem Endgerät und der Verwendung von tracking Technologien zu. Klicken Sie auf „MEHR INFORMATIONEN“ unten für mehr Informationen und Anleitungen wie man Cookies und tracking Technologien abschaltet. Das Akzeptieren von Cookies und tracking Technologien ist zwar freiwillig, das Blockieren kann aber eine korrekte Ausführung unserer Website verhindern, und bestimmte Werbung könnte für Sie weniger relevant sein.
Ihr Datenschutz ist uns wichtig. Lesen Sie mehr über unsere Datenschutzrichtlinien hier.