11 Replies Latest reply on Aug 22, 2019 9:14 PM by AH_96

    Sending information to the register at the address with the help of spi

    BUTA_1301626

      I have an RF transceiver module. this module has registers at certain addresses as in the picture.I want to load the values I want to these registers.

      SPIM_WriteTxData(0x35,0x14); ==>when I try this way, it gives an error.  (for example, this code works in arduino.)    in this code   address: 0x35 data: 0x14

      PSOC Device==>Master Device

      RF MODULE==> Slave Device

      What do I need to do to load 0x14 into the register at address 0x35?

      register.JPG

        • 1. Re: Sending information to the register at the address with the help of spi
          AH_96

          Hello BUTA_1301626

           

          Please refer this thread,Communication between two psocs with SPI

          Did the suggestion provided in the last comment work for you?

           

          SPIM_PutArray(const uint8/uint16 buffer[], uint8 byteCount) API will transfer the buffer array, which can hold the two data elements, 0x35 and 0x14 in this case, and this will transmit them one after the other.

           

          Please do try this out and let us know if it works in your case.


          Thank you

          Best regards
          Harigovind

          • 2. Re: Sending information to the register at the address with the help of spi
            BUTA_1301626

            Hi Harigovind;

            so you mean that;

            SPIM_PutArray(0x35,0x14);

                                       first address, second data

            Thank you

            Best regards

            • 3. Re: Sending information to the register at the address with the help of spi
              AH_96

              Hello BUTA_1301626

               

              SPIM_PutArray(const uint8/uint16 buffer[], uint8 byteCount) has 2 parameters:

              The buffer and the byte count.

                   const uint8 buffer[]: Pointer to the location in RAM containing the data to send

                   uint8byteCount: The number of bytes/words to move to the transmit buffer.

               

              In the case mentioned in the question, it is required to transmit 2 elements, the address and then the data. Therefore, the buffer[] in this case will hold these and bytecount will be 2.

               

              So, the code will be:

               

              uint8 buf[2] = {0x35, 0x14};

              uint8 byteCount = 2;

              SPIM_PutArray(buf, byteCount);

               

              This will transmit 0x35 and 0x14 to the slave device.

              Please refer the component datasheet for more details on the APIs.

               

              Also, please let me know the device that is being used. Is it a PSoC 5LP or a PSoC6.

               

              Thanks and regards

              Harigovind

              • 4. Re: Sending information to the register at the address with the help of spi
                BUTA_1301626

                Hello Harigovind,

                I've tried the following code. but I'm not sure if the result is correct.

                How can I tell if it is sent as [address data]?

                 

                LCD_PrintString("SPI MASTER:");

                       uint8 buf[2] = {0x35, 0x14};

                SPIM_PutArray(buf, byteCount);

                  uint8 buf2[2] = {0x25, 0x41};

                SPIM_PutArray(buf2, byteCount);

                Ekran Alıntısı.JPG

                Thanks and regards

                • 5. Re: Sending information to the register at the address with the help of spi
                  AH_96

                  Hello BUTA_1301626

                   

                  Please let me know the requirement of the host device. How does it expect data over the SPI bus? The SPI controlled in the PSoC device will only send the data. The host controller must be programmed to accept one as data and another one as address.

                   

                  There isn't a direct method to send one as address and another element as data.

                  If possible, share the bus information (required waveform) as required by your host device so that we can understand your requirement better.

                   

                  Thanks and regards

                  Harigovind

                  • 6. Re: Sending information to the register at the address with the help of spi
                    BUTA_1301626

                    Hello Harigovind,

                    In my project the rf transceiver will be slave. psoc device will master. I've attached the RF transceiver's datasheet.

                    Thanks and regards

                    • 7. Re: Sending information to the register at the address with the help of spi
                      AH_96

                      Hello BUTA_1301626

                       

                      As stated in this thread: Running hoperf on PSoC  you will need to change the arduino specific APIs to PSoC functions. We do not have a custom library for this device at the moment.

                       

                      Please note that all the APIs must be changed to PSoC specific APIs.

                       

                      Thanks and regards

                      Harigovind

                      • 8. Re: Sending information to the register at the address with the help of spi
                        BUTA_1301626

                        Hi,

                        I tried to implement the program to the PSoC device.

                        I get some errors during build.

                        --------------- Build Failed: 08/16/2019 16:13:38 ---------------

                        --------------- Build Started: 08/16/2019 16:13:58 Project: HOPERF_TX, Configuration: ARM GCC 5.4-2016-q2-update Debug ---------------

                        The code generation step is up to date.

                        arm-none-eabi-gcc.exe -mcpu=cortex-m3 -mthumb -I. -IGenerated_Source\PSoC5 -Wa,-alh=.\ARM_GCC_541\Debug/main.lst -g -ffunction-sections -ffat-lto-objects -Os -c main.c -o .\ARM_GCC_541\Debug\main.o

                        main.c: In function 'main':

                        main.c:35:33: warning: implicit declaration of function 'millis' [-Wimplicit-function-declaration]

                          unsigned long currentMillis = millis();

                                                        ^

                        main.c:47:20: warning: passing argument 1 of 'LCD_PrintString' makes pointer from integer without a cast [-Wint-conversion]

                            LCD_PrintString(cnt_tx++);

                                            ^

                        In file included from Generated_Source\PSoC5/project.h:31:0,

                                        from main.c:6:

                        Generated_Source\PSoC5/LCD.h:60:6: note: expected 'const char8 * {aka const char *}' but argument is of type 'unsigned int'

                        void LCD_PrintString(char8 const string[]) ;

                              ^

                        main.c:56:22: warning: passing argument 1 of 'LCD_PrintString' makes pointer from integer without a cast [-Wint-conversion]

                              LCD_PrintString(cnt++);

                                              ^

                        In file included from Generated_Source\PSoC5/project.h:31:0,

                                        from main.c:6:

                        Generated_Source\PSoC5/LCD.h:60:6: note: expected 'const char8 * {aka const char *}' but argument is of type 'unsigned int'

                        void LCD_PrintString(char8 const string[]) ;

                              ^

                        main.c:59:6: warning: implicit declaration of function 'LCD_PrintStringN' [-Wimplicit-function-declaration]

                              LCD_PrintStringN(rev_array, num);

                              ^

                        main.c: In function 'print_all_regs':

                        main.c:69:9: error: too many arguments to function 'SPIM_ReadRxData'

                          ret = SPIM_ReadRxData(i);

                                ^

                        In file included from Generated_Source\PSoC5/project.h:29:0,

                                        from main.c:6:

                        Generated_Source\PSoC5/SPIM.h:96:7: note: declared here

                        uint8 SPIM_ReadRxData(void) \

                              ^

                        main.c:72:2: warning: implicit declaration of function 'LCD_PrintStringn' [-Wimplicit-function-declaration]

                          LCD_PrintStringn(ret, HEX);

                          ^

                        main.c: At top level:

                        main.c:87:1: error: expected identifier or '(' before 'for'

                        for(;;)    {

                        ^

                        main.c:87:7: error: expected identifier or '(' before ')' token

                        for(;;)    {

                              ^

                        The command 'arm-none-eabi-gcc.exe' failed with exit code '1'.

                        --------------- Build Failed: 08/16/2019 16:13:58 ---------------

                        • 9. Re: Sending information to the register at the address with the help of spi
                          AH_96

                          Hello BUTA_1301626

                           

                          The arduino functions must be changed to PSoC compatible APIs.

                          Example: millis() is an Arduino function used to determine the time in milliseconds passed. This can be implemented using a timer and the counter value can be checked to obtain the time passed.

                          SPIM_ReadRxData() does not take any parameters, please refer the component datasheet for more details.

                          To print a number in LCD, you can use LCD_Printint32().

                           

                          Thanks and regards

                          Harigovind

                          • 10. Re: Sending information to the register at the address with the help of spi
                            BUTA_1301626

                            Hi;

                            I built it.but I'm examining it with a logic analyzer. no sign.

                            I can't find where I made a mistake. can you help me?

                            Thanks and regards

                            • 11. Re: Sending information to the register at the address with the help of spi
                              AH_96

                              Hello BUTA_1301626

                               

                              I tried to build the attached project but I am getting a lot of errors from the file HopeDuino_22b.c.

                              However, I see that the send_message function in the HopeDuino_22b.c file, which is actually responsible for transmitting the message over SPI uses a similar concept to what we had discussed in this thread.

                               

                              Please try to use this function in your end application. There are interrupt and data length packets in the function that do the specified function but it can be observed that the SPIM_PutArray() is used to transmit the address and the data in this case as well.

                               

                              Thanks and regards

                              Harigovind