Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > How can I send character until there's response ?

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



How can I send character until there's response ?
Moderator:
ARVI

Post Reply
Follow this topic



How can I send character until there's response ?

bianchi posted on 11 Mar 2013 6:59 PM PST
Top Contributor
168 Forum Posts

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 ");
     }




Re: How can I send character until there's response ?

bianchi posted on 11 Mar 2013 07:08 PM PST
Top Contributor
168 Forum Posts

can I do :

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



Re: How can I send character until there's response ?

bianchi posted on 12 Mar 2013 11:49 PM PST
Top Contributor
168 Forum Posts

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);
      }



Re: How can I send character until there's response ?

Bob Marlowe posted on 12 Mar 2013 01:17 AM PST
Top Contributor
1768 Forum Posts

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

 



Re: How can I send character until there's response ?

Bob Marlowe posted on 12 Mar 2013 02:56 AM PST
Top Contributor
1768 Forum Posts

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

 



Re: How can I send character until there's response ?

danaaknight posted on 12 Mar 2013 04:17 AM PST
Top Contributor
1773 Forum Posts

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.

 

 



Re: How can I send character until there's response ?

H L posted on 12 Mar 2013 05:17 AM PST
Top Contributor
679 Forum Posts

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);
}
          

 



Re: How can I send character until there's response ?

Bob Marlowe posted on 12 Mar 2013 07:16 AM PST
Top Contributor
1768 Forum Posts

@ 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



Re: How can I send character until there's response ?

bianchi posted on 13 Mar 2013 11:52 PM PST
Top Contributor
168 Forum Posts

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...



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 11:39 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 12:00 AM PST
Top Contributor
168 Forum Posts

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);



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 12:02 AM PST
Top Contributor
168 Forum Posts

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 ????

 



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 02:52 AM PST
Top Contributor
679 Forum Posts

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.



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 02:53 AM PST
Top Contributor
679 Forum Posts

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

 



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 04:15 AM PST
Top Contributor
168 Forum Posts

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

I don't understand now.....



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 04:17 AM PST
Top Contributor
168 Forum Posts

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



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 04:36 AM PST
Top Contributor
679 Forum Posts

 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. 

 

 



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 04:11 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I send character until there's response ?

danaaknight posted on 14 Mar 2013 05:13 PM PST
Top Contributor
1773 Forum Posts

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

 

Regards, Dana.



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 06:21 PM PST
Top Contributor
679 Forum Posts

Do not use the RFID now.

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



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 07:17 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 07:33 PM PST
Top Contributor
168 Forum Posts

this is PC to RFID module test :



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 07:43 PM PST
Top Contributor
168 Forum Posts

Video Test , PC to RFID module,

there's response

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



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 07:51 PM PST
Top Contributor
168 Forum Posts

I change command to 02

Photo :



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 08:58 PM PST
Top Contributor
679 Forum Posts

"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?

 



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 09:20 PM PST
Top Contributor
679 Forum Posts

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



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 09:30 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I send character until there's response ?

bianchi posted on 14 Mar 2013 09:31 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 09:44 PM PST
Top Contributor
679 Forum Posts

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.

 



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 09:49 PM PST
Top Contributor
679 Forum Posts

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,



Re: How can I send character until there's response ?

H L posted on 14 Mar 2013 09:53 PM PST
Top Contributor
679 Forum Posts

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. 



Re: How can I send character until there's response ?

bianchi posted on 15 Mar 2013 12:17 AM PST
Top Contributor
168 Forum Posts

can I use logic analyzer for it ?

replacing DSO ?



Re: How can I send character until there's response ?

H L posted on 15 Mar 2013 01:30 AM PST
Top Contributor
679 Forum Posts

 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.



Re: How can I send character until there's response ?

Bob Marlowe posted on 15 Mar 2013 01:54 AM PST
Top Contributor
1768 Forum Posts

@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



Re: How can I send character until there's response ?

bianchi posted on 15 Mar 2013 05:48 AM PST
Top Contributor
168 Forum Posts

Ok guys,

Project uploaded, hopefully you can find the answer,

thank you very much



Re: How can I send character until there's response ?

H L posted on 15 Mar 2013 06:22 AM PST
Top Contributor
679 Forum Posts

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

 



Re: How can I send character until there's response ?

Bob Marlowe posted on 15 Mar 2013 07:10 AM PST
Top Contributor
1768 Forum Posts

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?

 



Re: How can I send character until there's response ?

Bob Marlowe posted on 15 Mar 2013 08:02 AM PST
Top Contributor
1768 Forum Posts

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

 



Re: How can I send character until there's response ?

Bob Marlowe posted on 15 Mar 2013 09:50 AM PST
Top Contributor
1768 Forum Posts


Re: How can I send character until there's response ?

bianchi posted on 15 Mar 2013 09:25 PM PST
Top Contributor
168 Forum Posts

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 ?



Re: How can I send character until there's response ?

bianchi posted on 16 Mar 2013 10:55 PM PST
Top Contributor
168 Forum Posts

I tested on serial port,

It's not sending '01' but becoming 'F0',

any wrong setting ?

Thanks



Re: How can I send character until there's response ?

Bob Marlowe posted on 16 Mar 2013 12:52 AM PST
Top Contributor
1768 Forum Posts

Bianchi, as my crystal bowl tells me you are located in europe, germany. Since I use a cheap bowl it is not as accurate to tell me whether northern or southern parts of germany, but it shows some snow near you...

 

I am located near Bremen.

Back to PSoC: You still did not answer my questions concerning the hardware you use.

And as far as I understood, you managed to send chars already, I just changed the way to receive something, so it will be up to you to merge both parts and get your card-reader going..

 

Happy coding

Bob



Re: How can I send character until there's response ?

bianchi posted on 16 Mar 2013 04:02 PM PST
Top Contributor
168 Forum Posts

Back to PSoC: You still did not answer my questions concerning the hardware you use.

 

Bob, I'm using PSoC 1 board from Cypress,

and I live in Australia,

So what should I do next since the output is still F0, it's not 01 ?

Why is that ?

Have a good weekend



Re: How can I send character until there's response ?

bianchi posted on 16 Mar 2013 09:37 PM PST
Top Contributor
168 Forum Posts

There's no response on 'FE' or '01' input please see the picture

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

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

 

 



Re: How can I send character until there's response ?

Bob Marlowe posted on 17 Mar 2013 01:50 AM PST
Top Contributor
1768 Forum Posts

I'm going to dump that crystall ball!

So you have to go back to the basics.

First question (and please answer this time) Since you are using the 3210 development kit: Are the jumpers JP1 and JP2 set or not

Did you connect signals to J3?

 

Now to get things ready: Start a new project with LCD and UART (you can clone your current project) and connect the Tx pin of the PSoC directly to Rx. Send out one character and check if you receive it.

Next test lengthen the loopback to behind the level-shifter. Get yourself a 9-pin serial plug and bridge Pins 2 & 3.

Plug that onto your Kit and check if char is transmitterd  and received.

Connect a similar plug to your PC and verify that what goes out does come in.

Check with a multimeter which of the Pins from your PC-Cable has signal, Pin 2 or Pin 3

Let's see what results you've got.

 

Bob

 

 



Re: How can I send character until there's response ?

Bob Marlowe posted on 17 Mar 2013 01:57 AM PST
Top Contributor
1768 Forum Posts

.. and another hint: do not send "0x01" but a printable character as "X".

 

Bob



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 03:34 AM PST
Top Contributor
168 Forum Posts

First question (and please answer this time) Since you are using the 3210 development kit: Are the jumpers JP1 and JP2 set or not

Did you connect signals to J3?

 JP1 and JP2 are not connected and yes, I'm connecting signals to J3

So, I test it by connecting Tx to Rx direclty ( loop test ) ?

Thanks



Re: How can I send character until there's response ?

Bob Marlowe posted on 17 Mar 2013 08:13 AM PST
Top Contributor
1768 Forum Posts

So what pins did you connect to what numbers on J3?

 

Bob



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 04:14 PM PST
Top Contributor
168 Forum Posts

On J13

Tx -> P0.7

Rx -> P1.6



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 04:20 PM PST
Top Contributor
168 Forum Posts

Loop test like this :

LCD_1_PrCString("Sending 0x65");
 
    UART_1_PutChar(0x65);
           ucResponse = UART_1_cReadChar();
       
        Delay10msTimes(50);
        LCD_1_PrHexByte(ucResponse);
  

 

Let me see if ucResponse will give me something....I'm not sure yet before I test it...

 



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 04:35 PM PST
Top Contributor
168 Forum Posts

PSoC 1



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 04:38 PM PST
Top Contributor
168 Forum Posts

I'm really not sure that :

  ucResponse = UART_1_cReadChar();
       
        Delay10msTimes(50);
        LCD_1_PrHexByte(ucResponse);

UART_1_cReadChar(); doing its job,

I tried to send 85 from PC and display it on LCD, no response.....

WIth cable loop directly from Tx to Rx there's no response too.....LCD should display 65 if it's working.....

Is it possible if my hardware not working properly ? the PSoC 1 communication part ??



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 04:44 PM PST
Top Contributor
168 Forum Posts

A loop test

 

ucResponse = UART_1_cReadChar();
       
        Delay10msTimes(50);
        LCD_1_PrHexByte(ucResponse);
        UART_1_PutChar(ucResponse);
   

if there's character display it on LCD and PC



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 04:56 PM PST
Top Contributor
168 Forum Posts

a bit frustating for me only for a simple 1 character receive......

I'll do same test with other microcontroller and see what happens....

cypress API is not easy to use mate.....



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 07:20 PM PST
Top Contributor
168 Forum Posts

I'll wait for my logic analyzer coming, and see if my code is right or not...



Re: How can I send character until there's response ?

bianchi posted on 17 Mar 2013 07:20 PM PST
Top Contributor
168 Forum Posts

any of you guys have experience with UART like this ?

Please share if you have one ...thank you very much...



Re: How can I send character until there's response ?

H L posted on 17 Mar 2013 09:12 PM PST
Top Contributor
679 Forum Posts

I used the UART in the product and is in production for more than 2 years already.

I had in work with a much complicated protocol, so the UART UM is OK to use.

Did you used a different RX pin to test?

Did you use an LED with a series resitor as a logic indicator as suggest to check if the input pin is switching?

Have you download

http://www.cypress.com/?docID=33604

you may need to change to TX/RX pin for your project. 

It is not the same as yours, but you can use it to check how the UART functions.

You can at least confirm with there are problem with the PSoC or not as well as your I/O pins.

 

 

 



Re: How can I send character until there's response ?

H L posted on 17 Mar 2013 09:23 PM PST
Top Contributor
679 Forum Posts

One more thing to try.

Use the same set up as you are now, but discooonct the PSoC rx pin from the 232 chip FIRST, directly wire it to the TX pin of PSoC, you should then see there is ouput from TX by checking it on the PC, See if you get any thing on your UART RX.

If it fails, try to use another pin for RX input. See how it goes.

 

 



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 10:27 PM PST
Top Contributor
168 Forum Posts

Ok

I'm trying again

P2.7 = Tx

P1.6 = Rx

Spec of the card reader ,

I can connect directy to Tx and Rx, right ? without MAX 232, since it's TTL level already...



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 10:30 PM PST
Top Contributor
168 Forum Posts

RFID spec



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 10:40 PM PST
Top Contributor
168 Forum Posts

I can see from the reader, it's responding to 01 command, but I haven't got the result from the command displayed on LCD...

Please find the reader data sheet



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 10:44 PM PST
Top Contributor
168 Forum Posts

I tested with :

do {

        UART_1_PutChar(0x01);
        Delay10msTimes(50);

        /* do a read char, and display to LCD the char

        /* This is assuming RX to the UART is between 1 and 0xFF */
        ucResponse = UART_1_cReadChar();
       
        Delay10msTimes(200);
       
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrHexByte(ucResponse);
       
     

      }while (ucResponse == 0);

 

and want to display the response on LCD

Is there something wrong ? 

can anyone help ? thank you



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 10:45 PM PST
Top Contributor
168 Forum Posts

I put delay until 2 seconds in case a response from the card very slow..



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 11:09 PM PST
Top Contributor
168 Forum Posts

With :

P2.7 = Tx

P1.6 = Rx

even worse 00 00 00 00 00



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 11:21 PM PST
Top Contributor
168 Forum Posts

I short Tx and Rx on the board

P1.6 = Rx into P0.7 =Tx

 

Got no positive response yet.....I'm not sure "ucResponse = UART_1_cReadChar();" is doing the job



Re: How can I send character until there's response ?

H L posted on 18 Mar 2013 11:21 PM PST
Top Contributor
679 Forum Posts

I suggest not to try with the RFID until you can get the UART to receive a loop back signal or a signal from a Terminal software first.

The ouput of TX from PSOC is TTL level, so it can connect the TX to RX, just remember to disconnet the wire between you RX pin to the 232 output FIRST.



Re: How can I send character until there's response ?

H L posted on 18 Mar 2013 11:23 PM PST
Top Contributor
679 Forum Posts

Is your TX still connect to the 232? Did you see the output from PC?



Re: How can I send character until there's response ?

H L posted on 18 Mar 2013 11:26 PM PST
Top Contributor
679 Forum Posts

do {

        UART_1_PutChar(0x01);
        Delay10msTimes(50);

        /* do a read char, and display to LCD the char

        /* This is assuming RX to the UART is between 1 and 0xFF */
        ucResponse = UART_1_cReadChar();
       
  //      Delay10msTimes(200);/* *****not here****** */
        
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrHexByte(ucResponse);
        
       Delay10msTimes(200);/* should be here */

      }while (ucResponse == 0);

Also change the  Delay10msTimes(200) as indicated.



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 11:50 PM PST
Top Contributor
168 Forum Posts

There's no readchar in this link http://www.cypress.com/?docID=33604

 



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 11:55 PM PST
Top Contributor
168 Forum Posts

archive project,

Hopefully you guys can check out,

thanks



Re: How can I send character until there's response ?

H L posted on 18 Mar 2013 11:58 PM PST
Top Contributor
679 Forum Posts

There are different ways to read the RX buffer. Once your RX part working, you can change that.

You can try the project as suggest to test your hardware. and confirm your PSoC is still working OK.

For the time being, do it one at a time.

Can you see the TX on PC when connected TX to RX?

Did you use a logic indicator as suggest to check the signal?

 



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 12:24 AM PST
Top Contributor
168 Forum Posts

or just implement this one :

//----------------------------------------------------------------------------
// Mifare Read/Write RFID Module
// Model RFM015M-1
//----------------------------------------------------------------------------

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include <stdlib.h>

BYTE RxdataBuff[21];
BYTE sel_card[4]={0xBA,0x02,0x01,0xB9};      // Select Mifare card command  return 10 bytes
BYTE byte_length;
/*---------------------------------------------------------------------------------
void LCD_clr_line(unsigned char j)
function :     clear LCD on line number j (0 or 1)
input         line number j
----------------------------------------------------------------------------------*/
void LCD_clr_line(unsigned char j)
{
    LCD_1_Position(j,0);
    LCD_1_PrCString("                ");
}

void main()

    BYTE i;
    char Cardf_Str[] = "Selected Card  ";          // Card selected string for 0x00 status
    char Notag_Str[] = "No tag         ";          // No tag string for 0x01 status
        char Colli_Str[] = "Collision occur";           // Collision occur string for 0x0A status
        char Chksm_Str[] = "Checksum error ";           // Checksum error string for 0xF0 status
       
    LCD_1_Start();                // Initialize LCD
    UART_1_CmdReset();                // Reset Command Buffer
    UART_1_Start(UART_1_PARITY_NONE);        // Start UART
    LCD_1_Position(0,0);                // Set LCD position
    LCD_1_PrCString("BaudRate = 9600 ");
 

    while(1)
    {
        PRT0DR |=  0X80;
        while(PRT0DR & 0X80)         //Test tag detect signal
        {                //  low level indicating tag in detection range;
            LCD_1_Position(0,0);        //  high level indicating tag out.
            LCD_1_PrString(Notag_Str);    // Print "No tag" on the LCD  ;
        }
        UART_1_CmdReset();            // Reset UART Command Buffer
        for (i=0;i<4;i++)   
        {
            UART_1_PutChar(sel_card[i]); // Send a character to UART TX port
        }

        if(UART_1_cGetChar()==0xBD)
        {
            byte_length = UART_1_cGetChar();
            for (i=0;i<byte_length;i++)
            {
                RxdataBuff[i] = UART_1_cGetChar();    // Get a character from UART RX data register
            }           
            LCD_1_Position(0,0);
            switch(RxdataBuff[1])            // Check status byte
            {
                case 0x00:            // If 0x00 : Operation success
                    LCD_1_PrString(Cardf_Str);    // Print "Card selected" on the LCD  ;
                    LCD_1_Position(1,0);
                    LCD_1_PrCString("SN: ");
                    for (i=2;i<6;i++)
                    {           
                        LCD_1_PrHexByte(RxdataBuff[i]); // Print serial number of the card detected
                    }                   
                    break;
                case 0x01:
                    LCD_1_PrString(Notag_Str);      // Print "No tag" on the LCD  ;
                    LCD_clr_line(1);
                    break;
                case 0x0A:
                    LCD_1_PrString(Colli_Str);      // Print "Collision occur" on the LCD  ;    
                    LCD_clr_line(1);
                    break;
                case 0xF0:
                    LCD_1_PrString(Chksm_Str);      // Print "Checksum error" on the LCD  ;    
                    LCD_clr_line(1);
                    break;                           
            }
        }
        else
        {
            LCD_1_Position(0,0);       
            LCD_1_PrCString("Cardreader error");
        }
    }
}
 



Re: How can I send character until there's response ?

H L posted on 18 Mar 2013 01:50 AM PST
Top Contributor
679 Forum Posts

 I would suggest you go back to the one you used to send one character, wait a while, then read the RX buffer then print the buffer.

The more code you put it in,  the harder to debug and would increasing your frustration.

I suggest to try one SMALL step a time.  But it is your call. 

 

 



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 02:19 AM PST
Top Contributor
168 Forum Posts

I know that but I can not stand already, only receiving one character, it's been a week already, it's only a small easy one....and so difficult for me to implement....

If the code is wrong I'm opened to change or the hardware is not working properly ??? I bought it brand new from cypress...

I'll make the easiest task for this microcontroller, only receive 1 character nothing else it's very easy....



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 02:27 AM PST
Top Contributor
168 Forum Posts

I made it like this :

Very easy isn't it but never work on receiving character

//----------------------------------------------------------------------------
// Mifare Read/Write RFID Module
// Model RFM015M-1
//----------------------------------------------------------------------------

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include <stdlib.h>


/*---------------------------------------------------------------------------------
void LCD_clr_line(unsigned char j)
function :     clear LCD on line number j (0 or 1)
input         line number j
----------------------------------------------------------------------------------*/
void LCD_clr_line(unsigned char j)
{
    LCD_1_Position(j,0);
    LCD_1_PrCString("                ");
}

void main(void)

        char c;
   
     
    LCD_1_Start();                // Initialize LCD
    UART_1_CmdReset();                // Reset Command Buffer
     //Turn on interrupts
    M8C_EnableGInt ;
   
    //Enable RX interrupts
    UART_1_IntCntl(UART_1_ENABLE_RX_INT);
   
    //set parity as zero and start the UART
    UART_1_Start(UART_1_PARITY_NONE);
    UART_1_EnableInt();
   
    LCD_1_Position(1,0);                // Set LCD position
    LCD_1_PrCString("Enter char  ");
    UART_1_CPutString("Testing UART");
    UART_1_PutCRLF();
       
    while(1)
    {
        UART_1_CmdReset();                // Reset Command Buffer
        c = UART_1_cGetChar();
        UART_1_PutChar(c);
    }
 } 



Re: How can I send character until there's response ?

danaaknight posted on 18 Mar 2013 04:24 AM PST
Top Contributor
1773 Forum Posts

I think you should post a project so your settings can be looked at.

 

Regards, Dana.



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 04:40 AM PST
Top Contributor
168 Forum Posts

This one is working for me :

//----------------------------------------------------------------------------
// Mifare Read/Write RFID Module
// Model RFM015M-1
//----------------------------------------------------------------------------

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include <stdlib.h>


/*---------------------------------------------------------------------------------
void LCD_clr_line(unsigned char j)
function :     clear LCD on line number j (0 or 1)
input         line number j
----------------------------------------------------------------------------------*/
void LCD_clr_line(unsigned char j)
{
    LCD_1_Position(j,0);
    LCD_1_PrCString("                ");
}

void main(void)

        char c;
   
     
    LCD_1_Start();                // Initialize LCD
    UART_1_CmdReset();                // Reset Command Buffer
     //Turn on interrupts
    M8C_EnableGInt ;
   
    //Enable RX interrupts
    UART_1_IntCntl(UART_1_ENABLE_RX_INT);
   
    //set parity as zero and start the UART
    UART_1_Start(UART_1_PARITY_NONE);
    UART_1_EnableInt();
   
    LCD_1_Position(1,0);                // Set LCD position
    LCD_1_PrCString("Enter char  ");
    UART_1_CPutString("Testing UART");
    UART_1_PutCRLF();
       
    while(1)
    {
        UART_1_CmdReset();                // Reset Command Buffer
        c = UART_1_cGetChar();
        UART_1_PutChar(c);
        LCD_1_Position(1,0);                // Set LCD position
        LCD_1_PrHexByte(c);
    }
 } 

 

Now I need to move on with the card reader....

Could it be because of CmdReset ?

 



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 05:54 PM PST
Top Contributor
168 Forum Posts

If I tested on serial port to PC it's working allright, but when I tested to my card reader, it seems that it doesn't send 0x01 as expected....

Does anyone know why ?

I'll attach the project



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 06:04 PM PST
Top Contributor
168 Forum Posts

I tried to give repeat command and delay with loop

for (i=0;i<10;i++)   
                {
                  UART_1_PutChar(0x01);  //give command to the reader
                  Delay10msTimes(50);
                }
                c = UART_1_cGetChar();
                UART_1_PutChar(c);

 

I'll see the response from the reader, since it's working fine on PC serial port



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 06:11 PM PST
Top Contributor
168 Forum Posts

Guys,

It's responding to command 0x01, but why is it so slow in responding to "Card in" and "Card out" ?

any ideas ?

thanks



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 07:17 PM PST
Top Contributor
168 Forum Posts

I got the answer, make the delay faster,

do {

                  UART_1_CmdReset();                // Reset Command Buffer
                for (i=0;i<10;i++)   
                {
                  UART_1_PutChar(0x01);  //give command to the reader
                 
                  Delay50uTimes(1);
                }
                c = UART_1_cGetChar();
                 }while (c == 0);

 

And how can I get multiple char ?

thanks



Re: How can I send character until there's response ?

bianchi posted on 18 Mar 2013 07:34 PM PST
Top Contributor
168 Forum Posts

I want to send AB 02 01 and get the result AB 04 01 04 00,

How can I do that ?

Here's the datasheet...



Re: How can I send character until there's response ?

bianchi posted on 19 Mar 2013 10:31 PM PST
Top Contributor
168 Forum Posts

Is it possible for me doing like this ? I wanna take the first char from total five characters ...


do {

                                UART_1_CmdReset();                // Reset Command Buffer
            for (i=0;i<2;i++) //repeat command 15 times
              {
                for (i=0;i<3;i++)   
                {
                    UART_1_PutChar(sel_card[i]); // Send a character to UART TX port
                }
                  Delay50uTimes(1);

             }
               
                c = UART_1_cGetChar();
           
         }while (c == 0);
            byte_length = UART_1_cGetChar();
         for (i=0;i<byte_length;i++)
            {
                RxdataBuff[i] = UART_1_cGetChar();    // Get a character from UART RX data register
            }   
        if (RxdataBuff[0] == 0xAB) //check the first character
        {
         
         switch(RxdataBuff[1])            // Check status byte
            {
                case 0x04:            // If 0x04 : Operation success
                    LCD_clr_line(0); //clear LCD screen
                      LCD_clr_line(1);

                    LCD_1_PrCString("Card Selected");    // Print "Card selected" on the LCD  ;
                    LCD_1_Position(1,0);
                    LCD_1_PrCString("SN: ");
                    for (i=2;i<6;i++)
                    {           
                        LCD_1_PrHexByte(RxdataBuff[i]); // Print serial number of the card detected
                    }                   
                    break;
               
                case 0x02:            // If 0x02 : Operation fail
                    LCD_clr_line(0); //clear LCD screen
                      LCD_clr_line(1);

                    LCD_1_PrCString("Operation failed");    // Print "Card selected" on the LCD  ;
                           
                    break;
   
             }//end switch
        }//end if






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20