UART with BLE

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am trying to write firmware for the 244110 module. I have the dev board and the 042 programming board.

   

I have the BLE stuff all working. I am having trouble with the UART.

   

There are 2 example project for the 244110 when I create a new project. One is for transmitting and one is for receiving. Not sure why there isn't a single example that shows both, but ok. These examples use the LCD, which I don't have either, so I took that out.

   

I am trying to just send any data transmitted out back into the receive. I do this by just having a wire go from the TX pin to the RX pin. I am using pin P1.0 for RX and P1.1 for TX.

   

That is my first question. Should I have any trouble using those pins like that? Can I just connect them together and have the bytes go out one pin and come right in the other? I don't have an easy way to connect a serial port to my laptop, so I was hoping this would work.

   

I took the RX example and TX example and smashed them together and then modified the main.c to simply be this:

   

int main()

   

{   

   

    char8 ch;       /* Data received from the Serial port */

   

    char8 ch2;

   

 

   

    CyGlobalIntEnable; /* Enable all interrupts by the processor. */

   

 

   

    isr_1_Start();      /* Initializing the ISR */

   

    UART_1_Start();

   

 

   

    ch = 0;

   

    while(1)

   

    {

   

        ch++;

   

        

   

        UART_1_WriteTxData(ch); /* Sending the data */

   

 

   

        /* Check the UART status */

   

        ch2 = UART_1_GetChar();

   

 

   

        /* If byte received */

   

        if(ch2 > 0u)

   

        {

   

            CyDelay(200u);

   

        }

   

 

   

        CyDelay(200u);

   

    }

   

}

   

As you can see I just transmit a character and then try to receive it. Nothing ever comes in. I set a break point inside the if (ch2 > 0u) and it never hits the break point. This is similar to what I am seeing in my BLE firmware that tries to do the same thing.

   

I have attached a zip file to this post with the simple example project. Please tell me what I am doing wrong so I can get this working.

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Tony!

   

You started the interrupt, but you did not supply an interrupt handler, So the program will stall at the interrupt.

   

For the first approach I would suggest you to:

   
        
  • Remove the isr component
  •     
  • Change the Rx and Tx buffer sizes to 40. This will enable the component's internal interrupt handling.
  •     
  • Use UART_GetRxBufferSize() to check how many bytes are received already. This only works with the internal interrupts.
  •    
   

 

   

Happy coding!

   

Bob

View solution in original post

0 Likes
25 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Tony!

   

You started the interrupt, but you did not supply an interrupt handler, So the program will stall at the interrupt.

   

For the first approach I would suggest you to:

   
        
  • Remove the isr component
  •     
  • Change the Rx and Tx buffer sizes to 40. This will enable the component's internal interrupt handling.
  •     
  • Use UART_GetRxBufferSize() to check how many bytes are received already. This only works with the internal interrupts.
  •    
   

 

   

Happy coding!

   

Bob

0 Likes
Anonymous
Not applicable

Thank you for taking the time to respond. In my big project I had actually tried something like that and it didn't work.

   

I modified the sample that I have uploaded. I removed the isr component. I changed the RX and TX buffers to 40 and saw that the internal interrupts turned on.

   

I changed main to be like this:

   

 

   

int main()

   

{   

   

    char8 ch;       /* Data received from the Serial port */

   

    char8 ch2;

   

 

   

    CyGlobalIntEnable; /* Enable all interrupts by the processor. */

   

 

   

    UART_1_Start();

   

 

   

    ch = 0;

   

    while(1)

   

    {

   

        ch++;

   

        

   

        UART_1_WriteTxData(ch); /* Sending the data */

   

 

   

        if (UART_1_GetRxBufferSize() > 0)

   

        {

   

            /* Check the UART status */

   

            ch2 = UART_1_GetChar();

   

 

   

            /* If byte received */

   

            if(ch2 > 0u)

   

            {

   

                CyDelay(200u);

   

            }

   

        }

   

        

   

        CyDelay(200u);

   

    }

   

}

   

Same problem. I never reach the code inside the if (UART_1_GetRxBufferSize()) even though just above that I transmit a byte.

   

Where you able to get the sample I uploaded to work?

0 Likes
Anonymous
Not applicable

I have a little more information. I put a scope on the TX pin and do see the serial data going out, so I know the transmit is working.

   

I have the TX pin connected to the RX pin.

   

UART_1_GetRxBufferSize is always 0

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I changed the device to fit my board (CY8C4345AXI-483), removed the Rx pin and wired it internally to Tx signal.

   

Your supplied main() from last post runs flawlessly.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

As you can see from my post after yours (that we wrote at the same time) I did the same thing and having it wired internally works.

   

So the problem seems to be with the input pin not seeing the data.

   

So how do I fix it?

0 Likes
Anonymous
Not applicable

I just decided to try something else. I removed the RX and TX phyisical pins from the design and connected the UART RX and TX pins directly. Now I am getting the bytes back that I transmit.

   

Why can't I connect the physical TX and RX pins on the board and have that work?

   

I have the 244110 plugged into a 042 BLE kit board and am using that to program and debug it. I am using the header along the side of the board on P1.0 and P1.1. Are those not connected to the connectors that the 244110 are connected to?

   

Actually they must be because that is where I have the scope hooked up. So why don't I see the data coming in on P1.0 when I see it going out on P1.1?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Actually they must be because that is where I have the scope hooked up. So why don't I see the data coming in on P1.0 when I see it going out on P1.1 Only answer to this is a bad connection between P1_0 and P1_1.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I have the scope on the RX pin and am seeing the data on the scope, so I don't know how to connect it any more than that.

   

I have a jumper plugged into the header and the 2 pins are soldered together.

   

The only thing that makes sense is some kind of a problem with the RX pin config maybe?

   

Are you able to connect the 2 pins together physically on your board and have it work?

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yes, took some time to find a patch cable in the living-room. Changed back  to Rx and Tx pins an it worked. Project attached.

   

 

   

Bob

Anonymous
Not applicable

I notice that you have the isr routine in there. I thought you said to take that out.

   

If that doesn't matter then the only conclusion I can come to is that it has something to do with the 244110 specifically.

   

Where do I go from here?

0 Likes
Anonymous
Not applicable

I replaced my project with yours. Then I simply changed the device. Doing that gave an error when I compile saying that the input voltage of VDDA is set to 5 which is out of range. I fixed that by changing it to 3.3 and it compiles, but still the RX buffer is always 0 so it doesn't work.

   

Could this whole problem have to do with that voltage difference?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Take my running project, change the device to yours and try using a breakpoint.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

That is exactly what I did. Right after changing the device and trying to build I got an error that the VDDA was out of range. I changed it to 3.3, ran it and it didn't work just like mine.

0 Likes
Anonymous
Not applicable

I have to thank you for taking all the time you have to help. I hope you or someone can figure out why this doesn't work on my 244110.

   

I should also say that I tried other pins and still didn't get it working.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I would suggest you to get in contact with Cypress directly: At top of this page select "Design support -> Create a Support Case" and ask your question and attach your project archive. You will be helped by a Cypress engineer.

   


Bob

0 Likes
Anonymous
Not applicable

Again, you have been awesome helping on this. Thank you!

   

I have contacted my Cypress FAE. He is on it. I will try to remember to post the solution when we get to one.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

You are using the wrong pins.  P1(0) is not a Uart pin please check chart.

   

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Try this program and see if it works.

0 Likes
Anonymous
Not applicable

I kind of figured it might be something like that. Why did the tool let me choose it then? And it was green?

   

I will try out your example in a little while.

   

Thanks.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received
        That's a good question maybe Cypress can answer that   
0 Likes
Anonymous
Not applicable

I have everything working now. Much thanks to you and cypress FAE.

   

I do have another question if you know the answer.

   

I need to support write with response, but don't know the code to do the response. I set the BLE component with both write without response and then also write with response.

   

In my code I accept the data, but don't know how to acknowledge the write. I need to support both.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@bobgoar

   

The UART component in this project is UDB-based, so it can be routed freely to any port1, 2 and 3, No limitations for P1_0 and P1_1

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Sorry I wasn't clear in my last post. I am switching gears a little bit and talking about the bluetooth low energy. The code example I started with supports Write Without Response. I need to also support write with response, but don't know the code to write to perform the response.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Much thanks to you and cypress FAE    What did the FAE say?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

He sent me another example that I was able to modify. Basically the same thing you ended up helping me discover. I needed to use the SBC UART and put it on the right pins.

0 Likes