Menu

Low level serial not working for me

Help
GPS-tagger
2009-08-26
2013-05-30
  • GPS-tagger

    GPS-tagger - 2009-08-26

    I'm trying to use the low level serial routines to have an additional serial output.  I'm already succesfully using the USART TX & RX for another purpose so I can't use that and I don't want to buy a device with 2 USARTs as that'll lead to a number of other issues.

    I've tried the numerous code fragments I've found in this Help forum with no success at all.

    All I get ( when viewed in Bray Terminal ) is a continuous stream of binary zeros with the occasional garbage character.

    The output is going through a MAX232 ( also tried with a MAX3232 ) for testing purposes.

    I've tried the advice in this post :
    http://sourceforge.net/forum/message.php?msg_id=3966651
    altering the value of
    Sendr4800 = 21-40/ChipMHz
    as advised with no success.

    Suspecting that I had a timing error at 4MHz ( internal crystal ) or a hardware fault, I tried some assembler code from Nigel Goodwin's site and that worked perfectly ( albeit at 9600 instead of the 4800 I need to use ).

    This is my most recent attempt at getting this working :

    #chip 16F628A, 4
    #config OSC = INTOSC

    #define SendAHigh SET PORTB.6 ON 
    #define SendALow SET PORTB.6 OFF 

    ' ----------

    Dir PORTB.6 Out 'serial port out
    Dir PORTA.1 Out ' for LED

    InitSer (1, r4800, 1+WaitForStart, 8, 1, none, normal)

    wait 2 sec
    Start:

    SET PORTA.1 ON

    SerSend(1,35) ' just repeatedly send "#"

    wait 1 sec
    SET PORTA.1 OFF
    wait 1 sec

    goto Start

    The LED flashes as expected, but all I get in Terminal is continuous binary zeroes - even when the LED is off.

    Any help is much appreciated!

    Thanks.

     
    • GPS-tagger

      GPS-tagger - 2009-08-26

      I don't know what I was trying to say there.

      I get binary zeros when the LED is lit.  One byte per LED flash ( as expected ).  So it is sending, it's just that there's no data other than 0s.

       
    • kent_twt4

      kent_twt4 - 2009-08-26

      Here is the link to the contributors section that is a port of Nigel Goodwin's assembler to GCBasic http://sourceforge.net/forum/forum.php?thread_id=2155758&forum_id=629990

      Using a slow internal osc has always seemed to be a problem of sorts.  With a crystal oscillator, most of the time, the problem just goes away.

      With the aforementioned alternate soft Uart port, try using below code for setting up the baud of Ser_Init sub.
      ;try 4800 baud or 208us
      #define baud 206 ;or thereabouts
      #define halfbaud 103 ;place Read of SerRx in middle of bit

      For some reason my 'ol 16f648a is crapping out at 9600 buad with the alternate soft Uart routine and the 4Mhz internal osc....hmmm  With the 20Mhz crystal, it is good all the way up to 115200 baud in a simple loop back test, very impressive for a soft Uart.

      Here is the main code for the loop back test.

      'Chip model
      #chip 16f648a,20
      ;#config _INTRC_OSC_NOCLKOUT

      Ser_Init
      #define LED PortB.3 
      dir LED out

      start:
      Set LED On
      wait 1 s
      Set LED off
      wait 1 s
      Do
      ;Pic waits for signal from terminal/computer
      RCV_RS232            ;Return value is RxByte
      'Bin2ascii RxByte     ;echo back received string/ascii value
      XMIT_RS232 RxByte     ;echo back decimal value
      Loop
      goto start

       
    • GPS-tagger

      GPS-tagger - 2009-08-27

      That's fantastic.  My delay timing seems to be a bit off ( internal oscillator? ) and that's probably why the GCBASIC built in low level routines didn't work.  I just didn't go far enough on the timing changes.

      However, that code enabled me to track down a good delay ( 221us ) fairly easily and now it's working fine using that code instead of the rs232.h.

      Thanks again.  It is much appreciated.

       
    • GPS-tagger

      GPS-tagger - 2009-08-27

      I integrated this new code into my existing development and on testing I found the output to be garbage.  So, on a hunch, I took the delay back to 208us from 221us and all worked well again.  Same physical 16f628a as well.

      Oh well...

       
      • kent_twt4

        kent_twt4 - 2009-08-27

        That is odd.  Perhaps a pin had an extra load on it, or there was a partial short that heated up the chip?

        Hadn't noticed that the 16f628a family doesn't have an Osccal register.  You could change the frequency of the internal oscillator maybe 10-15% or so if it did.

        Glad it is working correctly now, and good luck on your project.

         

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.