View previous topic :: View next topic |
Author |
Message |
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
rs232 rx problems on 18f4520 |
Posted: Sat Mar 20, 2010 3:41 am |
|
|
Hallo,
I have a small issue, I have developed two different devices. Both are using rs485 bus to communicate with PC in asynchronous mode. One is based on 16F690 and another on 18F4520. The issue is that my code (below the post) works perfectly well on 16f690 but not on 18f... 18f is receiving data like 1 in 4 tries. I can't see why it is happening. TX works perfectly well. In both designs I use "MAX485 like chip" and connect it directly to pic. Another issue I have is TIMEOUT option in #use rs232, it stops 18f from receiving anything. When removed then all gets rolling.
My question is:
- USART - can it be directly connected to 485 chip (SL 81487E IPZ) or do I need signal shifter
- What can cause TIMEOUT to stop chip from receiving data (PCH 4.104).
Thank you for hints.
Code: |
#int_RDA HIGH
void comms() {
restart_wdt(); //clear WDT
int max_buffer = 0;
BYTE next_in = 0;
int c;
short d_flag = 0;
disable_interrupts(INT_RTCC);
do {
c = getc();
strn[next_in] = c;
next_in=(next_in+1);
max_buffer++;
if ((max_buffer == 15) && (c==13)) {
d_flag = 1;
flag_comms = 1;
}
} while ((c!=13) && (max_buffer < 16));
if ( (!kbhit()) && (d_flag == 0) ) {
rs232_errors = 1;
}
enable_interrupts(INT_RTCC);
disable_interrupts(int_rda);
}
|
_________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Sat Mar 20, 2010 5:13 am |
|
|
I have checked datasheets and my RX problem is related to ST = Schmitt Trigger input with CMOS levels so I need converter from TTL to CMOS. The board works well with 75176N. 16F690 must be a bit more tolerant to signal levels.
So there is only one question left to answer:
What is the difference when I use:
Code: |
#use rs232(baud=19200,xmit=pin_C6,rcv=pin_C7,parity=n,bits=8,stop=1,ERRORS,DISABLE_INTS,TIMEOUT=5)
|
on 16F690 (software UART) and it works,
and 18F4520 which is hardware UART. Why TIMEOUT=5 stops RX from working on 18F4520, I have downgraded to 4.088 to check if it is compiler but both creates the same effect.
Thank you _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Sun Mar 28, 2010 12:33 am |
|
|
Hello,
Small development in this, still can't find any answer to not working TIMEOUT option in #use rs232 on 18F4520 but I have found problem with comms on RS485. This is nothing to do with pull ups or ttl/cmos levels. Problem is in CCS and how it assembles code in PCM and PCH, I have found as well that D port has mixed pins in 18f4520.h. PCH in some cases is unable to transfer global vars to local function. I hope this findings saves a time for someone else having similar problem.
Regards _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
|