CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

2 USART PIC18F as interface between 2 devices

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Manel28



Joined: 06 May 2010
Posts: 33

View user's profile Send private message

2 USART PIC18F as interface between 2 devices
PostPosted: Thu May 06, 2010 3:48 am     Reply with quote

Hello,
I am new to microcontrollers I am going through the PIC slowly

I am having difficulty implementing a scheme with 2 devices and a PIC18F in between. The system consist of a device sending bits to one of the 18F USART at a given rate(19200bps). The PIC should receive the bits und keep them in a buffer. I suposse I can control the incoming flow with the RDA interruption. On the other hand the second USART must retransmit these bits in 100 bits packets which are sent every 40msec..I mean one 100bit packet every 40msec at a given rate.
Im not sure how can I implement the scheme becouse I dont know if I attend an interruption at the 2 USART to sent the packets every 40msec I can lose the incoming bits that are arriving at the USART 1. How can I implement this buffer or the scheme

Does anyone have a basic example that could help me figure out how this works??? Im sure this is a normal design.. like a keypad when we type and the words appear at the screen
Ttelmah



Joined: 11 Mar 2010
Posts: 19327

View user's profile Send private message

PostPosted: Thu May 06, 2010 4:28 am     Reply with quote

You need to start, by making sure that the hardware can actually 'do' what you are talking about....

You talk about 'sending bits'. The USART, doesn't really receive or transmit 'bits'. It sends _characters_. Normally 8bit, with an extra 'start bit' in front, and a 'stop bit' at the end (and potentially parity as well). Now, if your incoming stream does not have these extra start/stop bits, and your outgoing stream doesn't have them, then the USART is not going to do what you want.

If in fact the arriving stream, is orientated like this, and the outgoing stream also wants these, then things become possible.

What you would need to do, is look at ex_sisr.c, which shows an interrupt driven handler for a receiving UART, putting the data into a buffer. This would need to be modified to use a stream name, and talk to your first 'receive' UART.
Then you would have to look at EX_STISR.c, which shows an interrupt driven driver for a transmitting UART. Same comment applies about needing to modify to use streams.
Finally, you would program a timer, to generate a trigger event at 40mSec intervals. Probably use timer2, which is likely to be programmable to give exactly this interval. Then your 'main' code, can just sit in a loop, monitoring the timer2 interrupt flag, and when it triggers (implying that 40msec has passed), clear it, and just copy the buffered data from the receive buffer to the transmit buffer, and go back to waiting.

Best Wishes
Manel28



Joined: 06 May 2010
Posts: 33

View user's profile Send private message

PostPosted: Thu May 13, 2010 3:19 am     Reply with quote

Thanks! I forgot to say the communication should be full duplex becouse there will be a reply from the device B. I guess there should be any problem with the examples, just configuring int_rda and int_tbe at both USART.
Im still a lil bit confused.. but I think I will manage to do it
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group