Serial com PIC <> PC - what is best?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default Serial com PIC <> PC - what is best?

    Hello,

    I'm struggeling to get an error free serial communication between my 16F88/4MHz and the PC's terminal (using the MCS's one).

    The aim is to send data to the PIC's DATA memory and read it back in the PC.

    Actually, I'm transferring data kind of "one by one" memroy location basis and it works more or less fine. If I want to transfer to more than one memory location at the time, the trouble begins.

    I have read lots of threads about SERIN/SEROUT and the usage of USART. To be honest, the more I read, the more I get lost...

    My PIC is equipped with AUSART. Is this a "hardware" USART?

    What is the best and most reliable way to transmit data to and from the PC?
    Roger

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Serial comm handling is an endless story, there's tons of different ways, with check sum or not, with header/footer or not, split packets, use FlowControl pins etc etc.

    First of all, you must have a reliable PIC frequency. So, if it's not already the case, forgive the idea to use the internal OSC.

    Your PIC have a USART indeed, so forget the SERIN/SEROUT stuff, use HSERIN/HSEROUT instead. It have few advantage over SERIN/SEROUT.

    Now, depending what else your PIC do, you may miss some incomming data or not if you spend too much time here and there before the HSERIN... be carefull.

    You may decide to use a lower baudrate first.

    Post the code you have, it will be easier to figure this out together.
    Last edited by mister_e; - 1st January 2007 at 22:57.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Hello,

    I'm struggeling to get an error free serial communication between my 16F88/4MHz and the PC's terminal (using the MCS's one).

    The aim is to send data to the PIC's DATA memory and read it back in the PC.

    Actually, I'm transferring data kind of "one by one" memroy location basis and it works more or less fine. If I want to transfer to more than one memory location at the time, the trouble begins.

    I have read lots of threads about SERIN/SEROUT and the usage of USART. To be honest, the more I read, the more I get lost...

    My PIC is equipped with AUSART. Is this a "hardware" USART?

    What is the best and most reliable way to transmit data to and from the PC?


    Those example circuits in the PBP manual (without the RS232 converters) have always worked well for me.
    What kind of data are you trying to transfer? Bulk data, lots of info, single bytes, words, what?
    You'll probably end up writing your own version of FTP (flotulopex transfer protocol)

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Fill PIC's program memory

    I'll try with a 4MHz crystal.

    At the end, I want to send WORDs to the PIC's program memory. I tried this internally with WRITECODE and it works as long as 4 WORDs are stored in a row.

    I can't figure out how to send more than 1 data from the terminal to the PIC. So now, I have to press "Send" a couple of times until the LCD shows up some results. I send the datas comma separated, it this so?

    Since I'm testing step-by-step, I didn't made an endless loop.

    Here is the SERIN version:
    Code:
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
    @ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF
    
    ' Register settings
    OSCCON = %01100000  'Internal RC set to 4MHZ
    ANSEL  = %00000000  'Disable Analogue Inputs
    
    ' LCDOUT command (if defaults are not changed, DEFINEs can be omitted)
    DEFINE LCD_DREG PORTB       'LCD data port 
    DEFINE LCD_DBIT 0           'LCD data starting bit 0 or 4 on µC 
    DEFINE LCD_RSREG PORTA      'LCD register select port 
    DEFINE LCD_RSBIT 3          'LCD register select bit 
    DEFINE LCD_EREG PORTA       'LCD enable port 
    DEFINE LCD_EBIT 2           'LCD enable bit 
    DEFINE LCD_BITS 4           'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2          'Number lines on LCD 
    DEFINE LCD_COMMANDUS 2000   'Command delay time in us 
    DEFINE LCD_DATAUS 50        'Data delay time in us
    
    Value1   var WORD
    Value2   var WORD
    Value3   var WORD
    Value4   var WORD
    
    '-------------------------------------------------------------------------------
    ' Init LCD
    lcdout $FE, 1
    pause 1000
    
    '-------------------------------------------------------------------------------
    ' Input data from PC's terminal and show it on LCD
    serin2 PORTA.0, %100000001010100, [dec3 Value1] '9600, inverted
    serin2 PORTA.0, %100000001010100, [dec3 Value2] '9600, inverted
    serin2 PORTA.0, %100000001010100, [dec3 Value3] '9600, inverted
    serin2 PORTA.0, %100000001010100, [dec3 Value4] '9600, inverted
    lcdout dec3 Value1, " ",dec3 Value2, " ",dec3 Value3, " ",dec3 Value4
    END
    This is the HSERIN version, same problem as before:
    Code:
    @ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
    @ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF
    
    OSCCON = %01100000  'Internal RC set to 4MHZ
    ANSEL  = %00000000  'Disable Analogue Inputs
    RCSTA  = %10010000  'Enable serial port (RB2=RX & RB5=TX) and continuous receive
    TXSTA  = %00100000  'Enable Transmit Bit
    SPBRG  = 6          'Set baudrate to 9600
    
    DEFINE LCD_DREG PORTA       'LCD data port 
    DEFINE LCD_DBIT 0           'LCD data starting bit 0 or 4 on µC 
    DEFINE LCD_RSREG PORTA      'LCD "RS" register select port 
    DEFINE LCD_RSBIT 7          'LCD "RS" register select bit 
    DEFINE LCD_EREG PORTA       'LCD "E" enable port 
    DEFINE LCD_EBIT 6           'LCD "E"  enable bit 
    DEFINE LCD_BITS 4           'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2          'Number lines on LCD 
    DEFINE LCD_COMMANDUS 2000   'Command delay time in us 
    DEFINE LCD_DATAUS 50        'Data delay time in us
    
    '-------------------------------------------------------------------------------
    ' Init
    Value1 var WORD
    Value2 var WORD
    Value3 var WORD
    Value4 var WORD
    lcdout $FE, 1
    PAUSE 500
    
    '-------------------------------------------------------------------------------
    ' Input data from PC's terminal and show it on LCD
    Hserin [dec3 Value1] '9600, inverted
    Hserin [dec3 Value2] '9600, inverted
    Hserin [dec3 Value3] '9600, inverted
    Hserin [dec3 Value4] '9600, inverted
    lcdout dec3 Value1, " ",dec3 Value2, " ",dec3 Value3, " ",dec3 Value4
    END
    Attached Images Attached Images  
    Roger

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=flotulopex;30449]I'll try with a 4MHz crystal.

    Check the datasheet for the 16F88, page 100. You are using a 4mhz at 9600 baud. If you do the math, just like the datasheet says, you'll be 6.99% off at 9600 baud using the regular 'lo-speed' baud rate generator. Switch over to the high speed baud rate generator and you'll only be .16% off at 9600. Either that or switch down to 2400 baud and see what happens (.17% error at that speed with the lo-speed baud rate generator).
    If the 2400 works with lo-speed, do like I said (switch to the hi-speed BRG) and see what happens..

  6. #6
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Totally off topic

    If you plan to use WRITECODE you should be aware that some series require you to erase a block at the time and then write a block at the time. The size of these blocks can be found in the datasheet for the PIC. ERASECODE will erase the entire block that the address you have pointed to is inside.

    I just saw you said you wrote 4 words and that is not a good way later....

    /me

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    How many Bytes/Words you need to store to the PIC memory?

    Be aware, if you plan to use WRITECODE often, your PIC's life will be short...

    I also agree with the BRG setting, so i guess you wasn't aware of the PICMultiCalc?

    <img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1310&stc=1&d=116776697 4">

    Just click on the Copy PBP DEFINEs to clipboard button and paste the settings in your code. This software choose the best setting for you. Don't have to worry about using your calc or the datasheet Tables.

    The software is always available Here and it's free.
    Attached Images Attached Images  
    Last edited by mister_e; - 2nd January 2007 at 19:48.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Got it already ;-)

    I've got PICMultiCalc already (thank you for that, Mister_e).

    I plan to fill the PIC's program memory only once and store datas defenitively.

    The idea is to use it just like DATA memory.

    I imagine, the better and easier way would be to use a "smaller" PIC and add external serial memory...

    Actually, it is more about to learn how to use a PIC.
    Roger

Similar Threads

  1. PIC to serial with visual basic
    By mbw123 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 31st March 2007, 16:06
  2. High Speed Serial Comm PC - PIC and PIC - PIC
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 16th January 2007, 21:55
  3. Serial Communication (PC to PIC)
    By Simon Brodeur in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th January 2006, 18:55
  4. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 15:45
  5. Serial + Pic To Pic
    By chrispol in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th January 2005, 17:57

Members who have read this thread : 1

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