I want to configure the EUSART for full-duplex asynchronous mode and have the 18F4550 send the letter U to my Terminal.
Should I configure the pins like in traditional programs? The datasheet says that all I need to do is set TRISC, but should I mess with
PORTC and LATC?
Here are some additional features that need to be addressed according to the datasheet:
Automatic baud rate detection and calibration, automatic wake up on Sync Break reception and 12-bit Break
Character transmit.
-I wanted to set baud rate automatic detection but ric said it was a bad idea. I'm leaving the last two alone here
and assuming that they default to off.
Also from the datasheet:
The pins of the Enhanced USART are multiplexed
with PORTC. In order to configure RC6/TX/CK and
RC7/RX/DT/SDO as an EUSART:
• SPEN bit (RCSTA<7>) must be set (= 1)
• TRISC<7> bit must be set (= 1)
• TRISC<6> bit must be set (= 1)
The operation of the Enhanced USART module is
controlled through three registers:
• Transmit Status and Control (TXSTA)
• Receive Status and Control (RCSTA)
• Baud Rate Control (BAUDCON)
These are detailed on the following pages in
Register 20-1, Register 20-2 and Register 20-3,
respectively.
-I'm pretty sure I addressed all of this already.
vloki, I thought that my original baud rate calculation was correct. Here is my calculation:
For a device with FOSC of 8 MHz, desired baud rate of 9600, Asynchronous mode, 8-bit BRG:
Desired Baud Rate = FOSC/(64 ([SPBRGH:SPBRG] + 1))
Solving for SPBRGH:SPBRG:
X = ((FOSC/Desired Baud Rate)/64) – 1
= ((8000000/9600)/64) – 1
= [12.0208] = 12
Calculated Baud Rate = 8000000/(64 (12 + 1))
= 9615.38
Error = (Calculated Baud Rate – Desired Baud Rate)/Desired Baud Rate
= (9615 – 9600)/9600 = 0.16%
How does OSCCON even affect the EUSART? I couldn't find mention of it anywhere in the EUSART section.
I employed the preprocessor directive #define _XTAL_FREQ 8000000 in my .h file because that's what the Utube video said to do that got me this far.
I set the OSCCON register with 0b00000111 because vloki told me to do something to it and it seemed like a good idea. I read page 34 of that datasheet and got so excited that I went and changed things in my IDE right after the first mention of OSCCON, which is bits 2:0. If I would have read further, maybe I would have changed more stuff.
Honestly, I don't have a clue how to work this thing, there isn't any starter documentation anywhere that explains how to configure this, and I figured that this project was within reach before I started. I've done multiple things in AVR ASM, ADC stuff, Read Encoders, Comparator stuff and didn't have too much trouble. Am I wrong to try this and should I take a step back or in a different direction? What should I study?
vloki, Baud1USART()?? Where did that come from? I'm having trouble with a while(1) loop. In general, I'm confused about calling functions across files, multiple source files, advanced library functions, etc. The book I'm studying, C Programming, a modern approach, doesn't even get into stuff like this until the end of the book and It's UNIX specific. I tried reading the XC8 compiler documentation a few days ago and it's brutal for a noob like myself.