
Originally Posted by
manumenzella
... I think there is something i don't understand about the USART: is it like the serin/out, in which the pic has to do OLNY the serial transmission, and cannot do anything else, or is it like HPWM, a background process???
Manuel,
The harware USART operates in the background, as does the HWPM. However, you do have to "feed" it the data, and that will essentially happen one byte at a time.
You say you need to send 96 bytes at a time, twenty times a second? From your previous mention of 40MHz clock speed, I would deduce you are using an 18F PIC. I don't know how you are "gathering" your 96 bytes of data, but you could feed the USART from an array using interrupts to determine when the USART is able to receive the next byte. You may also be able to poll the TXIF bit frequently vs using interrupts.
Hopefully, this is not sounding too advanced. Start by reading the PBP manual on HSEROUT and the datasheet for you pic (the USART section). Also, MeLabs has some sample programs that can also help.
The basics are:
1) Setup the USART through the approapriate DEFINEs and registers. Here is an example of what I use for a 18F4620:
Code:
' 'Setup for 115200 baud
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 86 ' 86 = 115200 Baud @ -0.22%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
2) Use either:
a) HSEROUT to send out the data, realizing that it can do some processing of the data before it is sent to the hardware. Also, that sending multiple bytes of data will force the PIC to process all the bytes to be sent out before it moves on to the next statement
b) Send the bytes directly to TXREG. This would allow for the use of interrupts/flag polling to send the data "in the background"
Hope this helps you get started in the right direction.
Steve B
Guess I was a little slow on the draw
That's what happens when toddlers need to go to sleep!
Bookmarks