Learning how to use USART


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Learning how to use USART

    Strange baudrate !

    Using a EUSART calculator for your baudrate it gives these values for the port settings

    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 39  ' 31250 Baud @ SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $20   ' Enable transmit, BRGH = 0
    SPBRG = 39    ' 31250 Baud @ 0.0%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    I don't have PBP3 - so no idea if the formatting is the same or needs changing

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Learning how to use USART

    Please make sure that PIC to PIC directly connected work as expected.

    Then move to MIDI interface.

    Also be sure to connect TX to RX. Looks trivial but...

    Ioannis

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Learning how to use USART

    I removed the midi connections and just connected the TX of the transmitting PIC to the RC of the receiving PIC. Here is the code I'm using for each:

    transmitting:
    Code:
    define OSC 20
    define HSER_RCSTA 90h
    define HSER_TXSTA 20h
    define HSER_BAUD 31250
    DEFINE HSER_SPBRG 39  ' 31250 Baud @ SPBRGH = 0
    
    
    
    ANSEL = %00000000
    ANSELH = %00000000
    TRISD = %00000000
    TRISE = %00000000
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %10000000
    
    main:
    
    hserout [dec 1]
    PORTA.0 = 1
    pause 300
    hserout [dec 0]
    PORTA.0 = 0
    pause 300
    
    goto main
    receiving:
    Code:
    CLEAR
    define LOADER_USED 1
    define OSC 20
    define HSER_RCSTA 90h
    define HSER_TXSTA 20h
    define HSER_BAUD 31250
    define HSER_CLROERR 1
    DEFINE HSER_SPBRG 39  ' 31250 Baud @ SPBRGH = 0
    
    define LCD_DREG PORTD
    define LCD_DBIT 0
    define LCD_RSREG PORTE
    define LCD_RSBIT 0
    define LCD_EREG PORTE
    define LCD_EBIT 1
    define LCD_RWREG PORTE
    define LCD_RWBIT 2
    define LCD_BITS 4
    define LCD_LINES 4
    define LCD_COMMANDUS 2000
    define LCD_DATAUS 50
    
    ANSEL = %00000000
    ANSELH = %00000000
    TRISD = %00000000
    TRISE = %00000000
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %10000000
    
    character var byte
    
    pause 250
    lcdout $FE, 1
    lcdout $fe, $d4, "ready to receive"
    pause 500
    lcdout $fe, 1
    pause 250
    
    main:
    
    hserin [character]
    lcdout $fe, 1
    lcdout $fe, $94, dec character
    
    goto main
    So now it's sorta working. The LCD does display something. It displays "216" when it should be displaying "0" and it displays "217" when it should be displaying 1.

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Learning how to use USART

    Try setting a variable.
    Code:
    character  var word
    then use something like

    Code:
    hserout [dec character]
    And similar for the receiving pic. I'm no expert, but I think that just having DEC 1 as you had simply means its setting the DEC command to use just 1 digit as decimal value of a variable, not a value
    Last edited by Scampy; - 14th May 2018 at 20:44.

Similar Threads

  1. remote code learning
    By Bruce in forum Code Examples
    Replies: 20
    Last Post: - 21st February 2021, 15:38
  2. Replies: 7
    Last Post: - 12th January 2018, 17:02
  3. USB Learning
    By ruijc in forum USB
    Replies: 19
    Last Post: - 26th July 2014, 21:09
  4. Learning Basic
    By bartman in forum General
    Replies: 14
    Last Post: - 19th November 2004, 00:45

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts