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

Publié par

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.

 



Vidéos récentes

Désolé, le filtre sélectionné n’a renvoyé aucun résultat.

Nous avons mis à jour notre politique de confidentialité. Prenez un moment pour lire les changements. En cliquant sur "J'accepte", vous acceptez la clause de confidentialité d'Arrow Electronics ainsi que les conditions d'utilisation.

Notre site Internet place des cookies sur votre appareil pour améliorer votre expérience et pour améliorer notre site. Pour en savoir plus sur les cookies que nous utilisons et la façon de les désactiver, cliquez ici. Des cookies et des technologies de suivi peuvent être utilisés à des fins de marketing. En cliquant sur « Accepter », vous consentez au placement de cookies sur votre appareil et à notre utilisation de technologies de suivi. Cliquez sur « En savoir plus » pour de plus amples informations et instructions sur la façon de désactiver les cookies et les technologies de suivi. Même si l'acceptation des cookies et technologies de suivi est volontaire, leur désactivation peut entraîner un mauvais fonctionnement du site Internet et certaines publicités peuvent être moins pertinentes pour vous. Nous respectons votre confidentialité. Lisez notre politique de confidentialité ici.