basic UART question

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

cross mob
Anonymous
Not applicable

New to PSoC as maybe seen in a previous post, however I'm working with UART. I'm wondering why my if statements aren't getting any coming in true? I'm almost positive it's something simple. I looked at the datasheet for the UART module.

   

Essentially I'm looking for the status registers to be ready by polling(as asked for)

   


   

    uint16 readIterator=0;

   

    uint16 writeIterator=0;

   

    while(readIterator<4096){

   

        if(UART_ReadRxStatus()==UART_RX_STS_FIFO_NOTEMPTY ){

   

            receiveArray[readIterator]=UART_GetChar();

   

            readIterator++; 

   

            

   

        }

   

        if(UART_ReadTxStatus()==UART_TX_STS_FIFO_NOT_FULL ){

   

          UART_PutChar(sendArray[readIterator]); 

   

          writeIterator++;           

   

    }

0 Likes
10 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Its not enough to just post code to get help, generally speaking.

   

There are other issues that can affect troubleshooting, like HW

   

setup, etc..

   

 

   

    

   

          

   

Consider posting your project, makes life easier to troubleshoot.

   

 

   

“File”                                                             Creator

   

“Create Workspace Bundle”

   

 

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 I just realised I posted this in the wrong subforum, meant to post this is PSoC 5, but the file is attached.

   

Thanks for the timely reply.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Do you get inside the while loop ?

   

 

   

This has conflicting data types -

   

 

   

    uint8 sendArray[4096];
    uint8 receiveArray[4096];
    int i;
    for(i=0;i<4096;i++){
     sendArray=i;
     receiveArray=0;
    }

   

 

   

The pattern of 256 values in send array repeats 16 times because you declared it

   

as uint8.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You might also want to increase your heap size -

   

 

   

   

 

   

 

   

    

   

          

   

The heap and stack size were reduced in 3.1, try restoring to 3.0 levels 4K and 16K respectively.

   

3.1 default settings are now 128 bytes and 2K.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 So, I applied the changes as suggested, it seems smart to do. The problem that I'm having is, my program runs up to the while loop, and stays in the loop since neither of my if statements meet their conditions, so the program never advances past the while loop. 

   

what I should ask is:
How does the status register update? shouldn't the status register of the UART automatically update?

   

for example if I'm reading the status register of the UART transmit, with it being intialized, but not used, shouldn't the follwing if statement evaluate to being true?
 

   

if(UART_ReadTxStatus()==UART_TX_STS_FIFO_NOT_FULL){

   

 

   

}

   

or am I approaching this idea from a wrong direction?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I am stumped. If the Tx FIFO is full when you enter

   

the while, then nothing gets sent out. I looked at init

   

description, says nothing about clearing Tx FIFO, so

   

could it be full on startup ? Just a thought.

   

 

   

Maybe Bob can take a look at this. He knows quite a lot about

   

serial com.

   

 

   

Regards, Dana.

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

Thank you, Dana. I'm a bit late today, we had a great italian dinner yesterday evening...

   

What first jumps to my mind: Interrupts should be enabled (usually).

   

There is an error: insert a #include <stdio.h>
to have sprintf() resolved.

   

 

   

        if(UART_ReadTxStatus()==UART_TX_STS_FIFO_NOT_FULL ){
 

   

will fail: In the beginning, after initialization   UART_TX_STS_FIFO_EMPTY will be set, too so the result will never be equal to your questioned UART_TX_STS_FIFO_NOT_FULL.

   

Better use         if(UART_ReadTxStatus() & UART_TX_STS_FIFO_NOT_FULL ) which will be true, when the bit is set.

   

Same applies to _ReadRxStatus().

   

Lastly: in the embedded world you always hafe an infinite loop that repeats until powerr switched off. When your main() returns when reaching the end, do you know what will happen?

   

Better put an infinite loop at the end to wait or put the whole sending & revieving part into an infinite while-loop.

   

 

   

Happy coding

   

Bob
 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I looked at UART Init code, several ap notes, cannot see where

   

FIFOs get cleared ? So do they startup with "junk in them ?

   

 

   

Regards, Dana.

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

I trust in the underlying UDB or FF block will be cleared at initialization, I tested and after _Start() the FIFO flags show not full and empty, no errors set.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

I will post a case on this. No where in TRM, ap note on startup,

   

Datapath, etc.. does FIFO getting cleared stated.

   

 

   

Regards, Dana.

0 Likes