Serial Communications in PIC18F4550

Discussion in 'Embedded Systems and Microcontrollers' started by corsair, Apr 4, 2010.

  1. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    Hi guys,

    Me again :D and I'm in need of your PIC expertise. I have a problem that I'm working on for my class which states:

    I've never dealt with serial communications before, so I am honestly having trouble understanding what it's even asking. I had to actually look up what EUSART stands for, what the differences between parallel and serial are, what the PIC EUSART does (still fuzzy on this), what baud is, etc.

    So first of all, what does it mean to "initialize the PIC EUSART for 38400N81 communications?" I imagine this might be a type of communications protocol, but I'm not sure. Also, with serial communications, can I control my PIC board from my computer?

    Edit: So here's an explanation of problem 6 which might help to understand what he is asking. I have 8 switches (just buttons that I push), and a 4-digit, 7segment display. It is layed out such that there are 2 buttons under each digit. When I push switch1, it will increment digit1 on the display. If I push switch2, it will decrement digit1 on the display, switch 3 will increment digit2, etc.
     
    Last edited: Apr 4, 2010
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Hi corsair
    38400N81 should be equal to, 38400 bit per second, Non parity, 8 bit pr frame, and 1 is the same as 1 stop bit.
    In RS232 bitrate or baudrate will have the same meaning. The datasheet will give you info on how to setup your UART.
    Generally speaking, if your PC is equipped with a RS232 port. And your board also have RS232 port. The two devices can communicate, and hence the PC may control your board. To do RS232 communication with your PIC board. It must be equipped with TTL to RS232 level converter. A max232 circuit is often used for this purpose
     
    Last edited: Apr 4, 2010
    corsair likes this.
  3. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
  4. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    In mikroBASIC (or mikroC), you'd simply do:
    Code ( (Unknown Language)):
    1. UART1_Init(38400)
    Otherwise, you need to set the SPBRG, TXSTA and RXSTA registers accordingly. If you look at the 16F877A datasheet, it's all explained in chapter 10 - page 113.

    Hope this helps.
    Tahmid.
     
    corsair likes this.
  5. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    I got a couple of questions concerning setting up the serial communications. So, as mentioned above, I need this set up for:
    So here are my questions:
    So, if I want 38400 baud rate, this is equivalent to 9600 hex. I guess I just load 0x96 into SPBRGH and clear SPBRG, correct? Also BRG16 should be set. And what does the BRGH register do? Should this be set?

    Do I load data to the TXREG first then enable TXEN? Also, I was thinking about polling the TXIF. Will it automatically clear when finished? Do I have to worry about the stop bit or does it do that automatically?

    The way I'm going to practice this is that I will transmit a signal and receive it. Also, here are my settings for RCSTA. Please let me know if I should correct anything.

    bsf RCSTA,SPEN ; Enables Serial Port
    bcf RCSTA,RX9 ; Using 8-bit reception
    bsf RCSTA,CREN ; Enables Continuous Receive <-- should I turn this off when im done with it? and should this be on while i am transmitting? i figure since this is full-duplex it shouldnt matter

    When should I be checking the FERR/OERR bits?

    Umm.. yea I think that's it. It's so much to set up :confused:
     
  6. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Incorrect. Look at Table 20-1 and Example 20-1 and Table 20-3 to see how to calculate the correct values (in the datasheet)

    Look at the TXSTA: TRANSMIT STATUS AND CONTROL REGISTER description (Register 20-1)
     
Loading...