Rs232 PC-Pic problem


Closed Thread
Results 1 to 3 of 3
  1. #1
    andreq's Avatar
    andreq Guest

    Default Rs232 PC-Pic problem

    Hi,

    Recetly Ive been trying to create a small device to store some linux LOG data. As it send all the console text on a serial port, I'm trying to receive it on the pic, check for special char to stop the receiving and then store the data in the eeprom (the 128bytes of the pic for now) ...finaly write in the last eeprom space the place where it was last time.

    So trying it on windows with hyperterminal at 9600baud no parity 8bit inverted :

    I can send letter by entering them 1 by 1...send my special stop command (Enter + ~ ), receive the command ( s ... to send back the data to the pc) and this work.

    The problem comme when I send a text file. The pic seem to receive something.

    But when I ask the data ... i receive the first letter... + some weird thing...

    The pic seem to lose some of the data but as Im using CTS it should not...


    here is my last "working" code (using debugin as my last try..)


    include "modedefs.bas"
    TRISA = %11111111; ' Not really needed for now
    CMCON = 7
    lTemp var byte 'Temporary var for serial input
    Com0 var byte 'Special stop char 0
    Com1 var byte 'Special stop cahr 1
    Entrer var portb.4 'Not used with bebugin but was Input for serin..
    Sortie var portb.5 'output pin for serout
    PresEnv var portb.6 'CTS pin
    btEnvoyer var porta.1 'switch used to go in send mode on boot
    i var byte 'used to loop
    j var byte 'used to loop
    f var byte 'used to loop

    HIGH portb.2 'light a led on boot
    Com0 = 10 'Enter or Hx0A
    Com1 = 126 ' ~

    ' Set Debugin pin port
    DEFINE DEBUGIN_REG PORTB

    ' Set Debugin pin bit
    DEFINE DEBUGIN_BIT 4

    ' Set Debugin mode: 0 = true, 1 = inverted
    DEFINE DEBUGIN_MODE 1

    ' Set Debug baud rate
    DEFINE DEBUG_BAUD 2400


    main:
    if btEnvoyer = 1 then envoyer 'if switch is down then go in send mode
    i = 0 'set curent pos in eeprom to 0
    write 127,i 'write this pos in the last bit
    main2:
    high PresEnv 'toggle CTS on
    debugin [lTemp] 'receive 1 char.. and wait forever...until powered down
    low PresEnv 'toggle CTS off this method work... its like using the flowpin with serin2..
    if lTemp = Com0 then 'if Enter is received... wait for second special char
    high PresEnv
    debugin [lTemp]
    low PresEnv
    if lTemp = Com1 then 'if ~ is received go to command mode
    goto function
    endif
    endif
    write 127,i 'write curent pos in eeprom
    if i > 126 then 'eeprom is full minus 1
    high portb.3 'light the "off" led
    goto off1
    else
    write i, lTemp 'write serial data in eeprom (if not special)
    endif
    i = i + 1 'add 1 to curent pos
    goto main2

    function:
    high PresEnv
    serin Entrer,N2400,f ' wait for special command ...this code is working good
    low PresEnv
    select case f
    case "c"
    goto effacer
    case "s"
    goto envoyer
    case "x"
    goto main
    case "o"
    goto off1
    end select
    serout Sortie,N2400,["Erreur de code",13,10]
    goto function

    envoyer:
    read 127,i 'read curent pos in eeprom
    for j = 0 to i 'send each char 1 by 1 ...this work if data is not sent to fast first
    read j,lTemp
    pause 1
    serout Sortie,N2400,[lTemp]
    next j
    goto function

    off1:
    LOW portb.2
    off2:
    goto off2:


    effacer:
    for i = 0 to 127 'clear eeprom
    write i,0
    next i
    goto function



    If you could help me find what im doing wrong I would really apreciate.

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Voyons voir... mmm.

    As i already tested, CTS and other flow pin may react slower than you want. So may i suggest a special home brew PC software that you'll have to build?

    In fact, when i need to dump XYZ data, i build my VB program, The PC send XYZ function and sit for a PIC reply. The PIC sit for the PC data, the PC send the data finishing by a Checksum (or equivalent). When the serial timeout occur, the PIC do the checksum and TADA.

    Well, really rough explanation but it's suppose to be enough.

    Bonne chance!
    Steve

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

  3. #3
    andreq's Avatar
    andreq Guest


    Did you find this post helpful? Yes | No

    Default

    this woulnd be much of a problem... but I would also like to use the device to retreive some log out of Cisco Hub/Switch...witch is quite untouchable (9600 baud inverted)

    Ive actualy did not try the linux loging on serial port as my linux box was kinda acting weird... but as I said : sending a text file on hyperterminal or sending a file on linux (with miniport) send to fast... I'll retry to have a working linux loging systme on serial port but Im almost sure it will act the same.

    Anyway thanks for your answer!

Similar Threads

  1. RS232 into 2 PC ports
    By manxman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2008, 13:33
  2. Replies: 11
    Last Post: - 12th July 2008, 02:36
  3. PIC 18f1220 EUSART Baud Rate Cache Problem
    By wklose99 in forum Off Topic
    Replies: 3
    Last Post: - 15th April 2008, 00:39
  4. Interrupt and Serial communication to PC.
    By obaskirt in forum mel PIC BASIC
    Replies: 2
    Last Post: - 17th June 2005, 20:01

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