Y A Serial problem


Results 1 to 20 of 20

Threaded View

  1. #1
    jswayze's Avatar
    jswayze Guest

    Default Y A Serial problem

    I hate to do this given the amount of serial questions/answers out there, but I've been spinning my wheels and I could use a little help.

    I'm trying to send serial data from a Visual Basic program on my PC to my PIC. The data is in words, so I split it into high and low bytes.

    For illustrative purposes, I'm currently sending the values directly. In this case, I'm sending a decimal 258 which is b00000001 in the high byte and 00000010 in the low byte.

    My problem is with the PIC end I think. To visualize the actual values of the received data, I have an LED blink the value of the number. When I count the blinks, I get the high byte OK (in this case the LED blinks once) but I end up with double the low byte (4 blinks). Now I realize that this is simply a bit shift left of the low byte, but why is it happening, and why only on the second value?

    Here's the PIC code with the unimportant stuff removed. Oh, and I'm using a 16F628A with internal oscillator.

    Code:
    @ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF
    
    define OSC 4
    
    Baud CON 19697     ' 300 baud, inverted, N,8,1
    
    LED4 var PORTB.3
    
    serialData VAR byte
    serialHigh VAR byte
    serialLow VAR byte
    
    MAIN:
    
    '------------------------------
    'Check for setup mode
    '------------------------------
    
        SERin2 PROG,Baud,100,START,[wait(253)]  'wait 100ms see a 255    
        goto Program_Mode   
    START:
        'Do normal program stuff    
    goto MAIN
    
    Program_mode:
    
        SERin2 PROG,Baud,200,START,[wait(253) ]  'wait for the second of two 253s to start transmission
    
    '------------------------------------------------------------
    'Here is where the values are read in
    '------------------------------------------------------------
       SERin2 PROG,Baud,100,START,[serialHigh]
        tempword.Highbyte = serialHigh
    
        SERin2 PROG,Baud,100,START,[serialLow ]
        tempword.Lowbyte = serialLow
    
    '------------------------------------------------------------
    'Here is where the values are blinked out
    '------------------------------------------------------------
    if serialHigh = 0 then gohere
    for i = 1 to serialHigh
    high led4
    pause 20
    low led4
    pause 400
    next i
    
    pause 1000
    
    gohere:
    
    for i = 1 to serialLow
    high led4
    pause 20
    low led4
    pause 400
    next i
    
    goto main
    Can anyone help? Since it appears to be a bit operation, it seems it must have something to do with stop bits or the way the PIC is receiving the data. I just don't know.

    Oh, and there's been mention of a "binary mode" and "character mode" for serial communications... is there truly such a thing, and could this be part of my problem? Could I be receiving 7 bits instead of 8? I couldn't find any reference to these "modes" in the PBP manual.

    Thanks in advance for your help.

    -Jeff
    Last edited by jswayze; - 30th November 2004 at 05:24.

Similar Threads

  1. serial program and sensor problem
    By win_832001 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th April 2006, 04:16
  2. Replies: 5
    Last Post: - 20th March 2006, 01:34
  3. Serial Communication Problem
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 23rd February 2006, 02:11
  4. Replies: 8
    Last Post: - 11th November 2004, 20:08
  5. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 10:36

Members who have read this thread : 0

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