3 Replies Latest reply on Sep 27, 2015 2:02 PM by user_78878863

    SPIM_WriteTxData() Usage

    mnauss_1472621

      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

        • 1. Re: SPIM_WriteTxData() Usage
          user_365962704

          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

          • 2. Re: SPIM_WriteTxData() Usage
            mnauss_1472621

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

            • 3. Re: SPIM_WriteTxData() Usage
              user_78878863

              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.