- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi...
today i tried to read a 12 byte data with an UART component of Psoc3, for this i kept the settings of UART in RX mode as
9600 Bits per second (kept with reference to my RFID reader, which is the source for 12 byte data).
Data bits:8,
Parity type:None,
Stop bits:1
Flow control: None,
Clock Selection :Internal clock,
RX Address configuration:
Adress mode: None,
Advanced features:
Break signal bits: None,
Enable 2 out of 3 voting per bit, and disabled CRC outputs.
RX Buffer sizes:12 bytes,
Oversampling rate: 8X
and i have chosen an isr_1 component...
The basic problem what i am facing is, i have written an ISR in such a way that whenever my RFID reader (whose TX-OUT pin connected as RX pin of UART) detects the data, the control will transfer to ISR from main program and remains in ISR till it completes the reading of 12 bytes of data......
when it completes the reading of 12 bytes of data..the control is expected to return to main program..........till now everything is fine.....
but, when the control comes back to main program, it is expected to remain in the main program till the next interrupt occurs..... but, eventhough the control is properly coming back to main program, it is immediatly swithing over to ISR and remains there....
if i disable the ISR interupt, when my ISR routine is executing....after completion of ISR execution control coming back to main program and remains there...but it is not accepting the further interrupts...(as I disabled it).
If i re-enable the interrupt in my main program, the control is not remaining in main program, it is moving to ISR and stuck at one point as commented in the below code......
--------------------/* This is the part of main program which i am having problem*/--------------------------------------
for(;;)
{
// isr_1_Enable();
if(univ==1)
{
univ=0;
/* I WOULD LIKE TO DO MY TASK HERE */
}
}
-----------------------/* This is my ISR */-----------------------------------------------------------------------------------------------
CY_ISR(isr_1_Interrupt)
{
/* Place your Interrupt code here. */
/* `#START isr_1_Interrupt` */
/* Check the UART status */
/* Check the UART status */
univ=1;
isr_1_Disable();
/*---- This is where my control stuck when i uncomment // isr_1_Enable(); in main program. ----*/
for(i=0;i<12;)
{
ch = UART_1_GetChar();
// /* If byte received */
if(ch > 0)
{
text=ch;
i++;
}
}
/* Finally 'text' contains my received data, so that i can use it for further analysis */
/* `#END` */
/* PSoC3 ES1, ES2 RTC ISR PATCH */
#if(CYDEV_CHIP_FAMILY_USED == CYDEV_CHIP_FAMILY_PSOC3)
#if((CYDEV_CHIP_REVISION_USED <= CYDEV_CHIP_REVISION_3A_ES2) && (isr_1__ES2_PATCH ))
isr_1_ISR_PATCH();
#endif
#endif
}
Here i am beleiving that, once my RFID reader receives the 12 byte data, interrupt become enabled and the control moves in to ISR...whenever, it completes the execution of ISR it moves back to main program....but still the interrupt (which became active due to previous read of RFID data) is in active state, therefore it is immediately moving to ISR without staing in the main program....because of not having 12 byte data second time it goes....it remains stucked at that poit....
now, can any one help me how to make my code, to remain the control in the main program itself (when it comes back from ISR) untill the next interrupt comes..
NOTE: Here iam attaching a ZIP file...you can go through it.
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Data could be loaded in the array in the main loop. pl try the attached zip
regards
kavin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Data could be loaded in the array in the main loop. pl try the attached zip
regards
kavin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi kavin.....
there might be a problem in uploading ZIP file.............can you please send it to my mail ID: nanduksrmce@gmail.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The interrupt of the UART differs from your assumptions: When the RX-buffer is > 4 bytes an INTERNAL interrupt gets enabled and moves the reveived data from the UART to the buffer. You may check in your main-loop for any bytes received with the appropiate APIs as GetRxBufferSize().
You may hook into that internal interrupt, but this will appear at every char received..
Having problems to upload your project here?
In Creator
Build -> Clean Project (This reduces the amount of bytes)
File -> Create Workspace Bundle (minimal)
and then upload the resulting archieve here using ms Internet Explorer (you do not need to like it, but use it)
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are using Chrome for uploading any documents, it doesn't work well. Try uploading the attachment from IE/firefox.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Once again after looking into your sources: You assume that the Rx-interrupt gets fired after receiving the 12th character which is not true. It is an Rx-interrupt, so you'll get interrupted at every char.
Unfortunately I cannot correct your programs because you are using an outdated version of creator. I would suggest you to have your PSoC3 ES1 or two changed. There is an exchange program from cypress to handle that Later you can update to Creator 2.1.
Two corrections : To save one line, have a look at the API Isr_StartEx() which does exactly what you want with isr_Start() and isr_SetVector().
Wit6hin your ISR look ar UART_RxBufferSize() and set your flag when it is >=12
Oh, yes, DO NOT USE GLOBAL LOOP-VARS!!! This is not an error, but will lead to one after some time and expanding your program!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob give me some resource to learn about UART.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Sachinvbp, the following is a basic project you can look at -
http://www.cypress.com/?docID=36065
More general info -
http://www.freebsd.org/doc/en/articles/serial-uart/index.html
http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
http://www.freebsd.org/doc/en/articles/serial-uart/index.html
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi bob...
In your main3.ZIP
CY_ISR(Rx_ISR)
{
UART_ReadRxStatus();
if(UART_GetRxBufferSize() >= MessageLength) MessageReady = TRUE;
}
if i replace MessageLength with 11 (instead of 12)....then only it is expecting 12 bytes to get an interrupt.....
If i place Message Length as 12 (what u suggested), my program is expecting 13 bytes to get an interrupt......why it is happening....is buffer size starting from 0?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BufferSIZE counts from 1 on, zero means that no character is in the buffer. You should check which character (and why) you miss.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you may, you can post your current project here again to have us a look at.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Bob
here i am attaching my ZIP file...
here if i check with .........(UART_1_GetRXBufferSize>=11) in ISR, then it is expecting 12 bytes to make "card_detect=1"....and my code in main() is able to read the 12 bytes properly(what i am expecting to read).
but, if i write (UART_1_GetRXBufferSize>=12) in ISR, previously it was expecting 13 bytes...now it is expecting 24 bytes to make "card_detect=1"....and the code in main() is reading the last 12 bytes....I checked it repeatedly, all the instances are same....
i am expecting that...either some thing is missing or the settings of UART may be wrong....con you please correct it...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You put your code to set your variable card detect at the very begin of the interrupt routine before the actual character is retrieved and bufferted. So the actual char is not accounted for in the buffer. When you move your code to the end of the interrupt-handler into the marked area for "usercode required at end of isr" the counting will work correctly.
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi ...
till now i worked with psoc3 first touch starter kit (CY8CKIT-003). now i switched over to CY8CKIT-030. The problem is, when i am trying to run the same code (which i got executed with first touch kit) in CY8CKIT-030, i am not getting the intended output.....Tha basic problem which i am facing is...here i have used two UART components and my requirement is UART_1 should make the interrupt flag as 1, when it receives 12 bytes and UART_2 should make its related interrupt flag bit as 1 when it receives 1 byte.......The same i got when i executed this code with first touch kit.......but when i am trying to execute it with CY8CKIT-030... i am getting UART_1 Interrupt flag bit as 1 when it receives 4 bytes (expected to come with 12 bytes).....
here i am attaching ZIP file of my project....can any one please tell me what to do to make my UART_1 interrupt flag bit as 1 only when it receives 12 bytes......I am expecting that the problem may be with either the settings of UART_1 component or with the code i have written in UART_1_INT.c (line 168 to 172)
I have utilized this flag bit in main.c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When compiling your project I get 9 warnings which you should address. I gave the hint to increase the buffer's size from 12 to 24 just in case that something couldn't be read-out in time.
your code in the interrupt handler is quite clean, so when you insert a line like
Count = UART_1_GetRxBufferSize();
right after checking for card_detect you will see that there are 12 chars in the buffer.
There is a flaw in your code that "normally" does not matter, but when something goes wrong (and mr. Murphey says "It WILL go wrong") your program will stall.
In Access_Card_Comp.c line 242 you check for key_press==1. What if it is 2? better check for != 0 which could be expressed in C as
if(key_pressed)
which not only is safer but generates less code as well.
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@bob
Finally, the code is working to receive the twelve byte data perfectly for the first time.....but, from the second time it is failing to receive twelve byte data.....can you please justify whats the problem will be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Bob
Finally got the solution....I dont know what i did for it........any way i got it (without knowing the solution) and i dont know how long it will work properly....
hi bob, here i am attaching the ZIP file.....
the only modification that was needed to get the output is.....In line 96 of ACCESS_Card_Comp.c file i removed the string copy function......If am keeping this function, during the first attemp it is able to receive the 12 bytes and it is failing to receive 12 bytes in furthur attempts(it is receiving only 11 byte)....once after removing this function it is able to read 12 bytes always.....
i dont know what the problem lies in it....can you please tell me.....