Problem receiving data fron RS232 interface

Forum related to the FLEX boards

Moderator: paolo.gai

Locked
cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Problem receiving data fron RS232 interface

Post by cesiricerca » Thu Mar 12, 2009 2:49 pm

We are trying to use RS232 (UART) to communicate with an instrument. Our hardware is:
- dsPIC Flex Full board (Flex003)
- Flex Demo Daughter board (Flex109) with RS232 Module (Flex103) mounted.
We are able to correctly send data to the instrument, but we are not able to receive the answer from it (we have verified that
data are sent from the instrument).
We have used the Pic30 Serial evidence example.
We have verified that the function EE_UART2_Receive (from eeuart.h) return value \"-1\" (see part of code below)
if (U2STAbits.URXDA) {
*data = U2RXREG & 0x00FF;
return 0;
} else {
*data = 0;
return -1;
}
Please, someone can help us?

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re:Problem receiving data fron RS232 interface

Post by paolo.gai » Fri Mar 13, 2009 3:08 pm

Hi,

A few questions...

- Does the serial example as it is works for you??? I remember I have seen it working, but I also remember it uses only UART1 (probably we should check the UART2 code comparing it with UART1)

- Are you calling the receive inside a loop??? the function is non blocking, and if it returns -1 it simply means that there is no data on the UART2... and that you have to try later on.

- The Serial code has been reworked in the new version of ERIKA Enterprise, adding a console driver and many other things. I do not remember if the code ended up in the alpha release we put on the web a few days ago...

Ciao,

PJ

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem receiving data fron RS232 interface

Post by cesiricerca » Mon Mar 16, 2009 10:15 am

The serial example works using UART2 and SEND function only. Furthermore, as in the rs232 original example, we used loops (SetRelAlarm(AlarmSend, 500, 500) and SetRelAlarm(AlarmReceive, 500, 500).
We have verified that the instrument receive correctly the command and reply correctly, but we don\'t receive the answer in the UART buffer of the FLEX Demo Daughter board.
We tried to download EE 1.5.0 alpha, but it timed out (perhaps your server is too slow..).
Ciao

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re:Problem receiving data fron RS232 interface

Post by paolo.gai » Tue Mar 24, 2009 10:19 am

I spoke to some of the people in the ReTiS lab who are using the serial line together with the demo daughter board... but they seems to have no problems in using it. I\'ll ask them to post some code for you as a reference...

About the download of the alpha version,... did you manage to download it or it is still timing out?

Ciao,

Paolo

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem receiving data fron RS232 interface

Post by cesiricerca » Tue Mar 24, 2009 11:32 am

About the download of the Erika Enterprise 1.5.0 alpha: we tried today and the download worked fine. So we plan to try it next week.
Ciao

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem receiving data fron RS232 interface

Post by cesiricerca » Tue Mar 31, 2009 9:23 am

We have tried to run the rs232 test using EE 1.5.0 alpha. Nothing changed: the results are the same as using EE 1.4.3 (send OK, receive KO..).
Attached is the file code.c used.
Could someone help us?
bye
Attachments

[The extension txt has been deactivated and can no longer be displayed.]


chris
Newbie
Posts: 16
Joined: Mon Sep 29, 2008 1:27 pm

Re:Problem receiving data fron RS232 interface

Post by chris » Tue Mar 31, 2009 10:59 am

I tried the code you sent me, with EE 1.4.3. I just used the Multibus RT-Druid template, the one called \"Serial demo\", when I just replaced the code.c with the one you attached and I adapted the conf.oil to use the demodoard. On the pc-side I used the HyperTerminal (note that I already knew that the connection uart2-pc was working!).

The code works fine, of course the current behaviour in receiving mode is that of having the flex receiving in a non blocking manner! This means that you can see the \"recv=OK\" just while you press something in the HyperTerminal console, otherwise you receive nothing from the UART2 and the micro will sadly show \"KO\".

If you want to adopt(maybe just for testing?) a blocking mode you have to loop on the UART2 receive function, i.e. you should replace the code

Code: Select all


if (EE_UART2_Receive(&RXBuff) == 0) {
        EE_lcd_puts(\"OK \"«»);
} else {
        EE_lcd_puts(\"KO \"«»);
}
with this one

Code: Select all


unsigned long int cnt_limiter = 0;
while (EE_UART2_Receive(&RXBuff) != 0) {
        if (++cnt_limiter == 0) {
                EE_lcd_puts(\"KO \"«»);
                return;
        }
}
EE_lcd_puts(\"OK \"«»);
Note: this is a blocking version but includes a limit in the polling loop.
I hope this will help.
Please, can you meanwhile check if the receive line (from the micro point of view) is properly connected to the PC? Can you receive signals on the UART2_RX pin?

Cheers,
Christian.

cesiricerca
Newbie
Posts: 13
Joined: Wed Oct 29, 2008 1:49 pm

Re:Problem receiving data fron RS232 interface

Post by cesiricerca » Tue Mar 31, 2009 1:20 pm

We have modified the code according to your suggestions and all works fine! Thank you for your help.
Cheers
paolo

Locked