How can I send character until there's response ?

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

cross mob
Anonymous
Not applicable

Friends,

   

How can I send character until there's response ?

   

I wanna keep sending "UART_1_PutChar(0x01);" until there's response,

   

Anyone has idea for it ?

   

Thank you

   

 

   

Here's the code :

   

UART_1_PutChar(0x01);
   

    Delay10msTimes(50);
     
    c = UART_1_cGetChar();
       
      if (c == 0x01)
      {
        UART_1_CPutString("Char 0x01 accepted!");
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrCString("Card in ");
     }
     else
      if (c == 0xFE)
     {
        UART_1_CPutString("Char 0xFE accepted!");
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrCString("Card out ");
     }

0 Likes
82 Replies
Anonymous
Not applicable

can I do :

   

while(c==' ')
    {
     UART_1_PutChar(0x01);
    }

0 Likes
Anonymous
Not applicable

I tried to implement :

   

   

Am I putting the right code ?

   

because I can't get any response eventhough I put if (c !=''), it means RX always empty although I swing the card to the device ? any idea ?

   

UART_1_PutChar(0x01);
    
          c = UART_1_cGetChar();
     
      if (c !='')
      {
        P0_0(1);
        Delay10msTimes(100);
        P0_0(0);
      }

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

Bianchi,

   

I strongly suggest you to buy an ICE-Cube though it is not a cheap part. The ICE (In-Circuit-Emulator) is able to answer all your Questions within a few seconds and will help you to debug your program / Project within a few minutes so saving you days of trial and reeor. The debug capabilities for PSoC1 are very poor, but the ICE-Cube allows to put breakpoints to any C-line (or asm), inspect or alter variable values watch stack usage and even inspect a trace of the last instructions executed before a breakpoint.

   

I could not live without one, I bought mine together with my PSoC1 developement kit.

   

There is an actual offer from Cypress witch does not contain the first POD for the CY8C29466, but that would exactly be what you would need, so you ought to take the more expensive one.

   

Look at the specs here: http://www.cypress.com/?rID=3411

   

 

   

Bob

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

Since you are communicating with an external device and missing an answer from it, there is something amiss.

   

1. Can you post your COMPLETE project here, using the "Archive Project" function of Designer 5.3 (and using MS Internet Explorer, not Chrome!) by attaching the .zip with your post.

   

2. Do you use (does the card-reader need) a level-shifter for the RS232 signals

   

3. Is the card-reader connected via the 9-pin serial interface? If so

   

3a. Cable double checked? Compared to the PSoC-Kit schematics?? Jumpers???

   

3b. Is the card reader using control signals as CTS and RTS

   

 

   

As you see: Serial interface is always a vivid source of adventure, measurement and gnawing fingernails...

   

 

   

Bob

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

A minor point, change this -

   

 

   

      if (c == 0x01)
      {
        UART_1_CPutString("Char 0x01 accepted!");
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrCString("Card in ");
     }
     else
      if (c == 0xFE)
     {
        UART_1_CPutString("Char 0xFE accepted!");
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrCString("Card out ");
     }

   

 

   

to this

   

 

   

        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position

   

      if (c == 0x01)
      {
        UART_1_CPutString("Char 0x01 accepted!");
        LCD_1_PrCString("Card in ");
     }
     else
      if (c == 0xFE)
     {
        UART_1_CPutString("Char 0xFE accepted!");
        LCD_1_PrCString("Card out ");
     }

   

 

   

If you do not have a cube, start using your scope to see if your Rx character

   

is present. If its a DSO, many can extract clock to make life easy reading

   

character received. You can also start with a Designer supplied project

   

that is working and modify it bit by bit. When you open Designer, on opening

   

screen, is a group pf example projects in "Design Catalog" window.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Debugging communication software is not easy without ICE and CRO.

   

As others suggest get an ICE or/and a CRO.

   

for the time being.

   

void main (void)

   

{

   

usinged char ucResponse = 0;

   

/*** 

   

all other program to initalize the UART here 

   

 

   

***/

   

 

   

whie (1)

   

{

   

    ucResponse = 0;

   

   LCD_clr_line(0);
   LCD_clr_line(1);
   LCD_1_Position(0,0);                // Set LCD position 

   

   LCD_1_PrCString("Sending 0x01");

   

    do {

   

 

   

        UART_1_PutChar(0x01);
    

        Delay10msTimes(50);
      

   

        /* do a read char, if 0, send 0x01 again, else can start decode the reponse */

   

        /* This is assuming RX to the UART is between 1 and 0xFF */

   


        ucResponse = UART_1_cReadChar();

   

 

   

     

   

      }while (ucResponse == 0);

   

 

   

 

   

    LCD_clr_line(0);
    LCD_clr_line(1);
    LCD_1_Position(0,0);                // Set LCD position 
 

   

    
    if (ucResponse == 0x01)
    { 
       LCD_1_PrCString("Card in ");
    }
    else
    {

   

       if (ucResponse == 0xFE)
       {
           LCD_1_PrCString("Card Not in ");
       }

   

       else

   

       {

   

 

   

          LCD_1_PrCString("Unknown response ");

   

 

   

       }

   

    }

   

    /* Show the screen for 2 seconds */

   
         Delay10msTimes(200);   
   
    }   
   
                 
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@ Dana

   

Good idea!

   

But

   

The first character to send will be swallowed by the Tx buffer and the Putchar() returns. A second character to send would wait (blocking) for the last char beeing transmitted.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

still doesn't work guys,

   

I suspect the reader is not working properly, since I manually try it with Serial com TX and RX, sending it manually to the reader,

   

no response at all.....could be broken card reader...

0 Likes
Anonymous
Not applicable

Guys,

   

 

   

The code has been working until :

   

do {

   

 

   

        UART_1_PutChar(0x01);
    

        Delay10msTimes(50);
      

   

        /* do a read char, if 0, send 0x01 again, else can start decode the reponse */

   

        /* This is assuming RX to the UART is between 1 and 0xFF */

   


        ucResponse = UART_1_cReadChar();

   

 

   

     

   

      }while (ucResponse == 0);

   

 

   

 

   

but not responding to if

   

 

   

  if (ucResponse == 0x01)

   

 

   

looks like

   

ucResponse = UART_1_cReadChar();

   

 not doing its job ??

   

 

   

thanks

0 Likes
Anonymous
Not applicable

I tried to debug it, see below :

   

do {

 

        UART_1_PutChar(0x01);
   

        Delay10msTimes(50);
     

        /* do a read char, if 0, send 0x01 again, else can start decode the reponse */

        /* This is assuming RX to the UART is between 1 and 0xFF */


        ucResponse = UART_1_cReadChar();

   

       Delay10msTimes(50);
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrHexByte(ucResponse);

  

 

    

      }while (ucResponse == 0);

0 Likes
Anonymous
Not applicable

Guys, it's not reading anything,

   

always displaying 00 on LCD.....

   

it means

   


        ucResponse = UART_1_cReadChar();

       

   

is not doing its job.....why is that ????

0 Likes
Anonymous
Not applicable

If you read the data sheet:

   

char UART_cReadChar(void)

   

Read RX Data register immediately. If valid data is not available, return 0, else ASCII char between 1 and 255 is returned.

   

 

   

You are getting 0 means valid data is not available. 

   

Are you using a working card reader?

   

 

   

you need to read the data sheet and understand what is going on.

0 Likes
Anonymous
Not applicable

 The instuction is doing is job, it is saying that data is not valid.

0 Likes
Anonymous
Not applicable

I tested card reader with serial port and it's working as it supposed to be....

   

I don't understand now.....

0 Likes
Anonymous
Not applicable

I'll send you guys my video on testing it with serial port later on....

0 Likes
Anonymous
Not applicable

 In that case,

   

I will use the serial port from a PC, connect the 232port to your 232 input, run a program looping to read a char from the UART, with a delay loop to show the result when received. Then send a character from the PC.

   

Do the following:

   

1. Wirte a program to constantly sending out a charater from the PSOC to the UART may be once a second, if the realterm get the right charater, then the baud rate, parity and stop bit should be OK.. If not, then make sure wiring is correct, and there are signal going out from the 232 pin port pin. Change the baud rate, parrity and stop bit . you may need to check combinations.of the above If you cannot get this working, don't go to next step

   

2. Set your program to constantly reading the UART,  send a charter from the PC one character at a time. The PSoC program shouel print the received data when a charater is received. 

   

3. If you receve nothing, check the wiring and make sure signal goes to the psoc pin. Change the setting of the UART, most likely be the clock sync, or the RX inpput setting. DONT change the BAUD rate, don't change the stop bits and parity bits. 

0 Likes
Anonymous
Not applicable

Ok,

   

 

   

How can I connect it correctly ? from RFID module to PSoC module ?

   

is it

   

Rx to Rx and Tx to Tx or

   

Rx to Tx and Tx to Rx

   

 

   

Thanks

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

The Tx on PSOC goes to Rx on device, Rx on PSOC goes to Tx on device.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Do not use the RFID now.

   

Use the PC to check and make sure the UART is working first

0 Likes
Anonymous
Not applicable

Test between PC and PSoC board,

   

PSoC is sending 01 all the time,

   

but when I sent 01 from PC to PSoC board, it didn't give a proper response

   

Please have a look on the photo

   

0 Likes
Anonymous
Not applicable

this is PC to RFID module test :

   

0 Likes
Anonymous
Not applicable

Video Test , PC to RFID module,

   

there's response

   

http://s129.beta.photobucket.com/user/picture_77/media/PCtoRFIDtest_zps0c2a36d0.mp4.html

0 Likes
Anonymous
Not applicable

I change command to 02

   

Photo :

   

0 Likes
Anonymous
Not applicable

"Test between PC and PSoC board,

   

PSoC is sending 01 all the time,

   

but when I sent 01 from PC to PSoC board, it didn't give a proper response"

   

 

   

Question:

   

What do you expected from PSoC to reponse to the PC?

0 Likes
Anonymous
Not applicable

Did you follow what I suggested? and what did you see on the LCD when sending charater from PC to PSOC?

0 Likes
Anonymous
Not applicable

Question:

   

What do you expected from PSoC to reponse to the PC?

   

If I send 01 to PSoC from PC, PSoC will display 01 on LCD and print 01 into terminal in PC

0 Likes
Anonymous
Not applicable

Did you follow what I suggested? and what did you see on the LCD when sending charater from PC to PSOC?

   

Ans:

   

Yes I did, LCD gave no response when sending character from PC to PSOC

0 Likes
Anonymous
Not applicable

That means your TX side of PSOC is working, but thre RX side is not working.

   

1. Check if the wires are correct.

   

2. Check if there are signal on the PSOC input pin,( if you have aCRO, use a CR), if not you can use a LED with a 10k current limiting resistor, make sure the polarity is right ) you should be able to see a blink on the LED when PC sending data to PSOC, if not, check the circuit again.

   

3. If you can see the blinking, then check

   

the I/O option of the pin,

   

change the clock sync option of the UART,

   

change the designer to use another pin as the RX.

0 Likes
Anonymous
Not applicable

If you are making changes, Make ONE and only ONE change at a time. Mark down what happen with that change. If that change doesn't work, change it back to what it was (UNLESS you know it was wrong!), then change another possible options/ setting,

0 Likes
Anonymous
Not applicable

How about change the PSOC program to read RX only and print to LCD when received, Don't do any other things yet., dont send anything, just print what is received, display the data for 1 second, clear the LCD and repeat. 

0 Likes
Anonymous
Not applicable

can I use logic analyzer for it ?

   

replacing DSO ?

0 Likes
Anonymous
Not applicable

 Sure, set it up to trigger on the signal of the RX pin of PSoC,  you should be able to capture the data on the line, you can also check if it is the right timing and if pattern is correct.

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

@bianchi

   

90% of RS232 Errors are related to the cabling.

   

Which connections on your development kit 3210 are you using for the serial interface? JP1 & JP2 or Connector J13?

   

Are you using Port1 for any purpose?

   

I STRONGLY suggest you to upload an archive of your project here so that we can check all your settings. Use the "File -> Archive Project..." function in designer to accomplish that. Use MS Internet Explorer when uploading (NOT CHROME!!)

   

 

   

Bob

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

Ok guys,

   

Project uploaded, hopefully you can find the answer,

   

thank you very much

0 Likes
Anonymous
Not applicable

 Did you test the RX part only as I suggested. What is the result?

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

When you answer the questions...

   

I asked "Which connections on your development kit 3210 are you using for the serial interface? JP1 & JP2 or Connector J13?"

   

Or don't you use the 3210 Kit?

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

You enabled the command-line handler, but you did not work with commands. Using the high-level APIs makes it difficult to debug, better start with the low-level-APIs like reading status, writing one char and so on.

   

I disabled the command-handler and completed the UART properties you left blank, check if the beaveour changed.

   

 

   

Bob

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
0 Likes
Anonymous
Not applicable

Ok Bob,

   

Thank you very much for the suggestions and the project, I'm looking at it now...

   

I'll keep in touch....

   

Do you mind telling me where you are ?

0 Likes