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
Bookmarks