SPIM_WriteTxData() Usage

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello, I am new to embedded code and PSoC Creator as well. I am embarrassed to ask such a basic question but I must as I am just not sure how to proceed. I am using the SPIM component from the library and I want to communicate over the SPI to a MPL115A Barometer.

   

The format of the write is address then data, such as (0x20, 0x00). Now the description for the SPIM write function is as follows:

   

SPIM_WriteTxData() Places a byte/word in the transmit buffer which will be sent at the next available bus time. So how do I perform an address then data write, would it be 2 writes such as, void SPIM_WriteTxData (uint8, 0x20) then void SPIM_WriteTxData (uint8, 0x00)? this seems like the long way to do something. I have some sample code for the adruino that shows: write (0x20, 0x00).

   

So I am sorta confused. Any suggestions/help would be appreciated. I hope my question made sense. Also one more question, do I have to declare a function prototype for each SPIM function I use?

   

Thanks

0 Likes
1 Solution
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

xxx_WriteTxData have only 1 parameter (which can be uint8_t or uint16_t), that is the data value to transmit from the SPI, so you might use like this:

   

SPIM_WriteTxData (0x20);

   

SPIM_WriteTxData (0x00);

   

or you can put your data on a array and use xxx_PutArray(const uint8_t buffer[], uint8_t byteCount) function

   

parameter buffer[] is the name of your array, byteCount is the number of data to move to the transmit buffer

   

so you can do:

   

uint8_t data[2] = {0x20, 0x00};

   

xxx_PutArray(data, sizeof(data)); /* This function will place 0x20 and 0x00 on your trasmit buffer */

   

xxx is the name of your component on the schematic, when you place the component and configure, then you have to build the proyect, this will generate all the function available for the component, you can see them on the datasheet of each component or in the generated source files after the build process.

   

hope this help you

View solution in original post

0 Likes
3 Replies
cadi_1014291
Level 6
Level 6
25 likes received 10 likes received 10 likes given

xxx_WriteTxData have only 1 parameter (which can be uint8_t or uint16_t), that is the data value to transmit from the SPI, so you might use like this:

   

SPIM_WriteTxData (0x20);

   

SPIM_WriteTxData (0x00);

   

or you can put your data on a array and use xxx_PutArray(const uint8_t buffer[], uint8_t byteCount) function

   

parameter buffer[] is the name of your array, byteCount is the number of data to move to the transmit buffer

   

so you can do:

   

uint8_t data[2] = {0x20, 0x00};

   

xxx_PutArray(data, sizeof(data)); /* This function will place 0x20 and 0x00 on your trasmit buffer */

   

xxx is the name of your component on the schematic, when you place the component and configure, then you have to build the proyect, this will generate all the function available for the component, you can see them on the datasheet of each component or in the generated source files after the build process.

   

hope this help you

0 Likes
Anonymous
Not applicable

That's a big help, thank you very much.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

One caveat though: when using the SPIM-controller slave select line, it will go low when you are not deliverinbg new data to send fast enough. WriteTxData just fill bytes into the SPI FIFO, and when the FIFO is empty SS goes low.

0 Likes