Menu

can't get usart data to store

Help
2011-02-26
2013-05-30
  • Nobody/Anonymous

    here is my test code:

    #chip 16F688, 12 'mhz
    #config MCLRE=off, WDT=off
    #define USART_BAUD_RATE 9600  

    InitUsart
    On Interrupt UsartRX1Ready call serial_in
    lcdcon = 0 

    dim spot as byte
    spot=0
    'Set the pin directions

    dir portc.5 in ' serial
    dir portc.3 out ' led
    dir portc.1 out 'up

    'Main routine

    Start:
    set portc.3 on
    wait 100 ms
    set portc.3 off
    wait 100 ms
    goto start

    sub serial_in
    set portc.1 on
    if RCIF On Then serdata = RCREG
    epwrite spot, serdata
    spot = spot + 1
    end sub

    but i only get a few bytes stored no matter how many i send, but the heartbeat is still running so i know the chip is not locking up

     
  • Mauried

    Mauried - 2011-02-26

    The problem is trying to write to the EEPROM in the interrupt routine.
    Writing to EEPROM is a slow process.
    It takes 6 ms to write a byte, so at 9600 baud, the data is coming in too fast
    for the write to work, hence you will get unpredictable results.
    Write the data to the EEPROM outside the interupt routine,or reduce the baud rate to 1200 or less.

     
  • gcha44

    gcha44 - 2011-02-26

    Hi,
    Yes, I think Mauried is right , because   writing eeprom also call an interrupt  !
    So before you enable receiving any data and storing it in eeprom ,you must verify if last eeprom_write has finished with  for instance   :On Interrupt EepromReady  call verfying_eeprom_ready  (it's a suggestion)
    If usart-speed is higher than eeprom_write , try to store datas in an array before sending in eeprom
    Regards
    GC

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.