HSERIN problem


Closed Thread
Results 1 to 3 of 3

Thread: HSERIN problem

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Location
    The Netherlands
    Posts
    45

    Default HSERIN problem

    Hello everyone,
    I'm having trouble getting HSERIN to work properly, I think there is something I don't understand.
    I am controlling a DC motor through a Gamoto PID controller and want to read back the position. This is converted to a MIDI signal for use in a Max/Msp program. When I use the Serin2 command it works ok, but when I use the Hserin command my results are unpredictable, that is, I think I first get data that was left in the buffer and then the new data. The bytes are not in the correct order. If I leave out the CLROERR thing it does not work at all, so I think I get overflow errors. Any idea of how I can solve this? I would like to understand the Hserin command better so I can use that instead of the Serin2 command.
    Here's (part of) my code:

    @ device pic16F688, pwrt_on, mclr_off, protect_off, wdt_on, hs_osc
    INCLUDE "modedefs.bas"

    define OSC 20

    DEFINE HSER_ 1
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    RCSTA = $90 ' Enable USART RX
    TXSTA = $24 ' Enable USART TX
    SPBRG = 129 ' 9600 Baud
    OSCCON.3 = 1
    ANSEL = %10000000 'AN7 analog input
    ADCON0.7 = 1 '10-bit result right justified
    CMCON0 = %00000111 'comparators off
    PORTA = %00000000
    TRISA = %00000000
    PORTC = %00000000
    TRISC = %00111010

    ack var byte
    rx_data1 VAR BYTE 'received serial data
    rx_data2 VAR BYTE 'received serial data
    rx_data3 VAR BYTE 'received serial data
    checksum VAR BYTE
    position var word
    pos1 var byte
    pos2 var byte

    readpos:
    hSerOut [$AA,$82,$33,$03,$B8] 'send request for position
    hSerIn [ack,rx_data1,rx_data2,rx_data3,checksum]
    ' SerIn2 PORTC.5,84,10,readpos,[wait ($41),rx_data1,rx_data2,rx_data3,checksum]
    position = ((rx_data1>>4) + (rx_data2<<4)) + (rx_data3<<12)
    pos1 = position & 127 'split into two 7 bit position bytes
    pos2 = (position >> 7) & 127
    SerOut2 PORTC.2,12,[$90,pos1,pos2] 'send out midi
    pause 50
    goto readpos

    Any help is appreciated

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


    Did you find this post helpful? Yes | No

    Default

    When you're using HSERIN/HSEROUT, you also need to use the according define with, unless the baudrate will be 2400 Bauds.

    In your case @ 20 MHz you will need to use..
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Steve

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

  3. #3
    Join Date
    Oct 2007
    Location
    The Netherlands
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    Thank you Mr E for your reply
    I am using version 2.45 which has a bug so I cannot use the HSER defines with a pic16F688.
    I do use the DEFINE HSER_CLROERR 1 which works ok.
    Is there a way to clear the buffer before using the HSERIN command?
    thanks again

Similar Threads

  1. PIC16F88 HSERIN to LCD Problem
    By robbrownuk in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 6th June 2009, 22:32
  2. 16F877 HSERIN problem with 3th party software
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th March 2009, 17:11
  3. PIC HSERIN problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 20th July 2008, 11:08
  4. Replies: 3
    Last Post: - 12th February 2007, 18:32
  5. HSERIN problem
    By s_syafiq81 in forum Serial
    Replies: 2
    Last Post: - 1st January 2006, 11:05

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