1 2 Previous Next 17 Replies Latest reply on Jun 24, 2019 9:22 PM by MoTa_728816 Go to original post
      • 15. Re: How to send 1 byte as 8 bits
        BUTA_1301626

        I'm trying the following program. but the program does not run. I did the debug check.

        5 bytes 0x00 = 40 bit LOW                                   /

        4 bytes 0xFF and 1 byte 0xFE = 39 bit HIGH    / ==>I'm trying to check this  information.

        If this information is correct, I am trying to load the information that follows. but it's not working.

         

         

         

         

         

        uint8 CHECKSENC()

        {

        uint8 counthigh=0, countlow=0, SAY,iSay;

        for(iSay =0; iSay < 2; iSay++) {

        SAY = 0;

          SAY++;

        if (!SW_Read()) {

        if ((counthigh > 37) && (countlow > 38)) {

          return(1);

        }

        counthigh = 0;

        countlow++;

        }

        else {

        if (countlow < 38) {

        countlow = 0;

        return(0);

        }

        counthigh++;

        }

          while(SAY != 250);

        }

        return (0);

        }

        uint8 DATAOKURF(void)

        {

        uint8 DATABIT = 0x08;

        uint8 RF0=0;

        RF0 = RF0 << 1;

        if (DIO_Read())

        RF0 = RF0 | 0x01;

        else

        RF0 = RF0 & 0xFE;

        while(--DATABIT);

        return(RF0);

        }

        int main(void)

        {

            CyGlobalIntEnable; /* Enable global interrupts. */

        LCD_Start();

        CH_Write(1u);

        TR_Write(1u);

        CyDelay(100);

            for(;;)   {

        while(1){

         

        do{

        ISYNC = CHECKSENC();

        }

        while(!ISYNC);

        for(count=0; count < 10 ; count++)

        {

        RFBuffer[count] = DATAOKURF();

        }

        /* [] END OF FILE */

            }}

        • 16. Re: How to send 1 byte as 8 bits
          AH_96

          Hi

           

          In the code that is shared, the program will run into an infinite loop as the values are overwritten on each function call. That is, the variable countlow will never reach 38 and SAY will not reach 250 and this will cause the function to be stuck in an infinite loop.

           

          For the use-case that you have mentioned, please consider this article Controlling UART Tx and Rx Pins through Firmware for PSoC 4 Devices - KBA 224950 which explains the procedure to control UART pins through firmware when required and as UART pins otherwise.

           

          Do let us know in case of any further issues.

           

          Thanks and regards

          Harigovind

          • 17. Re: How to send 1 byte as 8 bits
            MoTa_728816

            Hi,

             

            Although Sending and Receiving Serial data by firmware need a couple of MCUs, this topic is in PSoC 6 Forum!

            And a PSoC 6 often has a couple of cores, Cortex-M0+ and Cortex-M4.

            So I tried let Cortex-M4 send bytes, and let Cortex-M0+ to receive them.

            It's great that we can test with only a single board ;-)

             

            I used CY8CKIT-062-WIFI-BT

             

            The schematic was (connect P0[2] and P5[6] to let cores communicate)

            001-schematic.JPG

            002-PinList.JPG

             

            Cortex-M0+ main.c

            =================

            #include "project.h"

            #include "stdio.h"

             

            #define BIT_DELAY 10

            #define SW_LOW  (0u)

            #define SW_HIGH (1u)

             

            #define delay(a)  CyDelayUs(a)

             

            char str[128] ; /* print buffer */

            void print(char *str)

            {

                UART_PutString(str) ;

            }

             

            void init_hardware(void)

            {

                __enable_irq(); /* Enable global interrupts. */

                UART_Start() ;

                /* Enable CM4.  CY_CORTEX_M4_APPL_ADDR must be updated if CM4 memory layout is changed. */

                Cy_SysEnableCM4(CY_CORTEX_M4_APPL_ADDR);  

            }

             

            void splash(void)

            {

                sprintf(str, "Software Serial Test (%s %s)\n", __DATE__, __TIME__) ;

                print(str) ;

            }

             

            uint8_t sw_recv_byte(void)

            {

                int bit_count = 8 ;

                uint8_t data = 0 ;

              

                while(Cy_GPIO_Read(SW_RX_0_PORT, SW_RX_0_NUM) == SW_HIGH) {

                    delay(BIT_DELAY/2) ;

                }

                delay(BIT_DELAY) ;

                while(bit_count--) {

                    data <<= 1 ;

                    if (Cy_GPIO_Read(SW_RX_0_PORT, SW_RX_0_NUM) == SW_HIGH) {

                        data |= 0x01 ;

                    }

                    delay(BIT_DELAY) ;

                }

                if (Cy_GPIO_Read(SW_RX_0_PORT, SW_RX_0_NUM) != SW_HIGH) {

                    print("SW_RX, Stop bit missing!\n") ;

                }

                return( data ) ;

            }

             

            int main(void)

            {

                uint8_t data = 0 ;

              

                init_hardware() ;

              

                splash() ;

             

             

                for(;;)

                {

                    data = sw_recv_byte() ; /* this function blocks */

                    sprintf(str, "\tCM0 received 0x%02X\n", data) ;

                    print(str) ;

                }

            }

            =================

             

            Cortex-M4 main.c

            =================

            #include "project.h"

            #include "stdio.h"

             

            char str[128] ; /* print buffer */

            void print(char *str)

            {

                UART_PutString(str) ;

            }

             

            #define BIT_DELAY 10

            #define SW_LOW  (0u)

            #define SW_HIGH (1u)

             

            #define delay(a)  CyDelayUs(a)

             

            void sw_send_byte(uint8_t byte_to_send)

            {

                uint8_t mask = 0x80 ;

             

                Cy_GPIO_Write(SW_TX_0_PORT, SW_TX_0_NUM, SW_LOW) ; /* start bit wannabe */

                delay(BIT_DELAY) ;

                while(mask) { /* sending 8 bits MSB first */

                    if (byte_to_send & mask) {

                        Cy_GPIO_Write(SW_TX_0_PORT, SW_TX_0_NUM, SW_HIGH) ;

                    } else {

                        Cy_GPIO_Write(SW_TX_0_PORT, SW_TX_0_NUM, SW_LOW) ;

                    }

                    mask >>= 1 ;

                    delay(BIT_DELAY) ;

                }

                Cy_GPIO_Write(SW_TX_0_PORT, SW_TX_0_NUM, SW_HIGH) ;  

                delay(BIT_DELAY) ; /* stop bit wannabe */

            }

             

            int main(void)

            {

                uint8_t byte_to_send = 0x00 ;

              

                __enable_irq(); /* Enable global interrupts. */

             

                Cy_GPIO_Write(SW_TX_0_PORT, SW_TX_0_NUM, SW_HIGH) ;

              

                CyDelay(1000) ; /* wait for Cortex-M0 to be ready, may be too much */

             

                for(;;)

                {

                    sprintf(str, "CM4 sending 0x%02X\n", byte_to_send) ;

                    print(str) ;

                    sw_send_byte(byte_to_send) ;

                    byte_to_send = (byte_to_send + 1) % 0x100 ;

                    CyDelay(1000) ;

                }

            }

            =================

             

            The debug output via Tera Term was

            000-TeraTerm-log.JPG

             

            As far as I tried, 2us for 1 bit did not work, but so far 10us for 1 bit seems to be working.

            As usual, your mileage may vary

             

            moto

            P.S. Alas, this was the first program I intentionally used both cores of PSoC 6 orz

            1 2 Previous Next