USB Serial Communication Continuous


Closed Thread
Results 1 to 17 of 17

Hybrid View

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

    Default

    I've never tried with a DEFINE OSC 20... but i think it's the main problem.

    Look how i did it in mine. (config fuse as well)

    and now
    Code:
    DoLow:
    LOW PORTC.0
    USBSERVICE
    PAUSE 30
    USBSERVICE
    return

    This example don't use instant interrupt, inserting a PAUSE and using On INTERRUPT GOTO might cause some problem for the USBSERVICE.

    next point...i don't know what's happen if you use both HSER_BAUD and HSER_SPBRG together... Assuming HSER_SPBRG may override the HSER_BAUD, you have a big problem as your SPBRG value is way out of range @20MHZ... but good @8MHZ.

    to have 2400 baud @20MHZ, you should use...
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 129 ' 2400 Baud @ 20MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    I do believe the HSER_CLROERR may help a little bit.

    There's probably something else... i feel a bit lazy today
    Last edited by mister_e; - 10th February 2007 at 19:03.
    Steve

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

  2. #2
    Join Date
    Feb 2007
    Posts
    11

    Default

    Quote Originally Posted by mister_e View Post
    I've never tried with a DEFINE OSC 20... but i think it's the main problem.

    Look how i did it in mine. (config fuse as well)
    I have tried it with a DEFINE OSC 48 as well....infact the USB interface works fine...i tried to switch on/off the LED pins on you demo and they work ...

    The config fuses are
    24 0E 3E 00 00 83 81 00 0F C0 0F E0 0F 40

    in either case (48 or 20)
    i have defined the PLL and OSC setting in the .inc file so the DEFINE directive has no effect


    in the case of :

    DoLow:
    LOW PORTC.0
    USBSERVICE
    PAUSE 30
    USBSERVICE
    return

    i found that this code does work...and it does generate a delay of 30ms on the Oscilloscope without affecting the Tx USB connection....The TX seems to be transmitting fine...
    Last edited by pic-ker; - 10th February 2007 at 19:01.

  3. #3
    Join Date
    Feb 2007
    Posts
    11

    Default

    Quote Originally Posted by mister_e View Post
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 129 ' 2400 Baud @ 20MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically

    I do believe the HSER_CLROERR may help a little bit.
    Thanks, I'll try that now...
    Last edited by pic-ker; - 10th February 2007 at 19:17.

  4. #4
    Join Date
    Feb 2007
    Posts
    11

    Default

    I havre tried all the above statements....

    DEFINE HSER_CLROERR 1 is now inculded...

    however im still getting errors...
    i transmit : 239 65 66 67
    I receive : 254 254 6 134 128
    (5 chars for tx of 4 chars)

    maybe its because i used SEROUT in conjunction with HSERIN ?

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

    Default

    And... do you get always the same results or they are always different?
    Steve

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

  6. #6
    Join Date
    Feb 2007
    Posts
    11

    Default

    Differnet results each time...


    Anyway I have finally got the TX/RX to work !

    Heres the section of the TX code which works:

    IF USBBufferIn[7]=239 then
    SEROUT PORTC.0,T2400,[USBBUFFERIN[7]]
    gosub DoLow
    USBBufferin[7]=0

    if USBBufferIn[1]<>0 then
    SEROUT PORTC.0,T2400,[USBBufferIn[1]]
    gosub DoLow
    USBBufferIn[1]=0
    endif
    USBService
    if USBBufferIn[2]<>0 then
    SEROUT PORTC.0,T2400,[USBBufferIn[2]]
    gosub DoLow
    USBBufferIn[2]=0
    endif
    USBService
    if USBBufferIn[3]<>0 then
    SEROUT PORTC.0,T2400,[USBBufferIn[3]]
    gosub DoLow
    USBBufferin[3]=0
    endif
    USBService
    if USBBufferIn[4]<>0 then
    SEROUT PORTC.0,T2400,[USBBufferIn[4]]
    gosub DoLow
    USBBufferin[4]=0
    endif
    USBService
    if USBBufferIn[5]<>0 then
    SEROUT PORTC.0,T2400,[USBBufferIn[5]]
    gosub DoLow
    USBBufferin[5]=0
    endif
    USBService
    if USBBufferIn[6]<>0 then
    SEROUT PORTC.0,T2400,[USBBufferIn[6]]
    gosub DoLow
    USBBufferin[6]=0
    endif
    USBService
    endif

    gosub dousbin


    goto start

    DoLow:
    USBSERVICE
    PAUSE 65
    USBSERVICE
    return

    Notes:
    1. You need to use the T mode if you are directly connecting PIC's.
    2. Notice the Pause 65 - It now works great with a longer delay...and has no effect on the USB connection.


    Heres part of the modified RX code :

    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Define HSER_RCSTA 90h
    Define HSER_BAUD 2400

    The oscillator is set to 20Mhz in both cases using : DEFINE OSC 20
    __________________________________________________ _______________

    Now that the wired link is working....I checked it using a FSK TX/RX pair
    and the problems are endless....
    Completely random characters etc
    Characters appear when i move my hand in the air !
    I have tried a passive Bandpass filter around 2400hz but it doesnt sove the problem...
    I have connected a Schottky TTL gate to the DataOut...for maintaining proper level transitions...
    Also when I connect a LED to the DataOut of the RX it keeps flickering at a fast rate (around 10kz on the oscilloscope),even when the Tx is off...which is probably whats causing the errors..

    Any ideas on how to fix this ? or is the RF module faulty ?

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default

    pic-ker, I bet the RF receiver module you are trying to use has no squelch control and the toggling of the receiver output is the data slicer trying to interpret noise. You will have to put some kind of sync and preamble bytes in place before you transmit the data and, if the sync and preamble bytes are not received in order and correctly you should not accept the data. This is the common problem people have when using inexpensive rx and tx modules. Even with more expensive modules the same sync/preamble techniques should be used. Also you should send a computed checksum as the last byte and this checksum should be checked at the receiver end before using the data received.

    Dave Purola,
    N8NTA

  8. #8
    Join Date
    Feb 2007
    Posts
    11

    Default

    Quote Originally Posted by Dave View Post
    pic-ker, I bet the RF receiver module you are trying to use has no squelch control and the toggling of the receiver output is the data slicer trying to interpret noise. You will have to put some kind of sync and preamble bytes in place before you transmit the data and, if the sync and preamble bytes are not received in order and correctly you should not accept the data. This is the common problem people have when using inexpensive rx and tx modules. Even with more expensive modules the same sync/preamble techniques should be used. Also you should send a computed checksum as the last byte and this checksum should be checked at the receiver end before using the data received.

    Dave Purola,
    N8NTA
    Yeah, youre right, the module was really cheap ... it doesnt have a crystal based oscillator, rather there is an inductor coil which can be adjusted by a screwdriver....

    I think it would be better if I get another module :-) instead of doing all that syncing/CRCing etc

Similar Threads

  1. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 18:03
  2. Serial data to USB
    By cooksydesign in forum USB
    Replies: 18
    Last Post: - 29th October 2008, 16:10
  3. USB and serial cable connection(s)
    By ardhuru in forum Schematics
    Replies: 3
    Last Post: - 18th August 2008, 16:26
  4. Bafo USB to serial adapter
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 29th July 2006, 19:48
  5. Serial to USB converter
    By jrt4fun in forum USB
    Replies: 6
    Last Post: - 8th August 2005, 16:14

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