Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

SAVE RS232 data to pic 16f84

Status
Not open for further replies.

hitch

New Member
Hi all

I am using oshonsoft pic sim.
I need to save a "file" from pc to pic, comms are ok but i can only receive 1byte every 2sec.
this make transfers of 40bytes ! very slow.

any ideas on how to improve my code?
pic uses a 4mhz 3pin resonator and i have max232 on the comms. sending to the pc is no problem and receiving also works but sloowly.

code:
datareceive:
'serial input
memloc = 0
serb = 20

'while serb > 10
For i = 0 To 30
Serin PORTA.2, 2400, serinbyte
WaitMs 500 'tried different delays between rec.
serdata(i) = serinbyte
'looks for a % to signal end of trans.
If serinbyte = 37 Then i = 60
'Wend
Next i

'just a bit of comms from the pic to ack end
Serout PORTA.3, 2400, "end"

'made this a sep function coz i first thought that writing to eeprom would take longer than writing to the ram.
'write to onboard eeprom
For i = 0 To 30
Write i, serdata(i)
WaitMs 500
PORTB.2 = Not PORTB.2
Next i
Return

code end :

Any one with suggestions please. i have successfully (with gr8t help) added a 24lc256 into the mix, and i do not want to be writting 10Kb files at 1byte every 2sec.
 
hi hitch,
That program is incomplete..
Post the FULL program, use the '#' symbol on the menu bar to load CODE, it keeps the format.

EDIT:
Look at this version, it works OK in a PIC
Code:
Dim inp As Byte
Dim out As Byte
Dim serinbyte As Byte
Dim serdata(30) As Byte


loop:

inp = 1
datareceive:
Serin PORTA.2, 2400, serdata(inp)

If serdata(inp) = "%" Then
Goto xmit
Endif
inp = inp + 1
Goto datareceive

xmit:
For out = 1 To inp
Serout PORTA.3, 2400, serdata(out)
Next out

Serout PORTA.3, 2400, CrLf
Goto loop


End

Sample of RS232 i/o. it works at full speed of 2400baud OK, no missing data.
Yellow is data from PC to PIC , the green data is received data back at PC.
 

Attachments

  • hitch02.gif
    hitch02.gif
    15.1 KB · Views: 305
Last edited:
eric

as always your code is brill and simplistic. I have quick question, if you have a byte array with 30 elements. why am i able to send the following string - which is 37 bytes?? "123456789012345678901234567890123456%"
I send that string and it echo's back. I am having to put my bad habit VB coding aside and start "learning" this pic basic.

i tried writing to eeprom (24c256) after the serin function, but the i loose input. I am trying to send a small text file to the pic and then "retrieve" it later so i thought of saving direct but maybe i will have to implement basic h/w handsaking to tell the pc to hold on sending till write is complete, I would then perform a write every 30 bytes then when done set the flag to receive again. or am i missing something?
 
Last edited:
eric

as always your code is brill and simplistic. I have quick question, if you have a byte array with 30 elements. why am i able to send the following string - which is 37 bytes?? "123456789012345678901234567890123456%"
I send that string and it echo's back. I am having to put my bad habit VB coding aside and start "learning" this pic basic.

i tried writing to eeprom (24c256) after the serin function, but the i loose input. I am trying to send a small text file to the pic and then "retrieve" it later so i thought of saving direct but maybe i will have to implement basic h/w handsaking to tell the pc to hold on sending till write is complete, I would then perform a write every 30 bytes then when done set the flag to receive again. or am i missing something?

hi,
You can use CTS/RTS hardware handshaking on the PC's UART/RS232 control, use PIC pins to sense the CTS/RTS states.
The MAX232 as you know has 2 each i/o line drivers/receivers, so you should have two spare MAX pins.
My advise would be not to use software hand shaking ie: ackon, ackoff, by the time it works the RX buffers will have overflowed.

Ref the over-length TXD string, depending upon the transmission rate of the PC, if slow enough, it will sometimes work, I would limit the TXD string to 30 bytes or less.
You could use CrLf as the end of text [EOT] delimiter in place of the '%' character, just test for LF [ 0x0a]

If the EEProm text files you are 'storing' are fixed data strings, they could be loaded into program memory during programming the PIC and recalled by a 'token' byte received on the PIC's RXD line.
 
hi
I was hoping it was a timing issue that could be solved in program. My current attempt at avoiding more hardware conversion is to make my vb comms app send 30bytes at a time wait xx then resend the rest of the file. The pic will be connected to cnc machine where we will dump the file but that cnc mach. only uses 3wire comms. so the rts/cts will only be used when i transfer the file to the pic. - is there a simple way to convert serout to use 7E1 instead of 8N1, my current attempt involves searching for the char with odd bits and manually adding the parity bit. when i try on my system is "seems" to work, but i just wanted to be sure there wasn't maybe another way.

thanks for the info.
 
hi
I was hoping it was a timing issue that could be solved in program. My current attempt at avoiding more hardware conversion is to make my vb comms app send 30bytes at a time wait xx then resend the rest of the file. The pic will be connected to cnc machine where we will dump the file but that cnc mach. only uses 3wire comms. so the rts/cts will only be used when i transfer the file to the pic. - is there a simple way to convert serout to use 7E1 instead of 8N1, my current attempt involves searching for the char with odd bits and manually adding the parity bit. when i try on my system is "seems" to work, but i just wanted to be sure there wasn't maybe another way.

thanks for the info.

hi,
I have been checking for changing to 2400,e,7,1 in the OS Basic, I cannot see any option to do that.
If it is vital that you have the option to choose the Parity etc, I would recommend that you use a 16F628A PIC, which has an internal 4mHz clock and a hardware USART.
The 16F84 is 'old' and limited....
The other option is to write your programs in assembler or 'C'
 
I will be upgrading my pic start as soon as i get the part. then i will be using the 628 and others coz i am totally excited with using these pics.
the cnc machine only "accepts" limited chars, so i just use the byte.x command to update an odd byte to an even. since the 8n1 and 7n1 both send the same amount of bits i am hoping the cnc will accept it.
 
I will be upgrading my pic start as soon as i get the part. then i will be using the 628 and others coz i am totally excited with using these pics.
the cnc machine only "accepts" limited chars, so i just use the byte.x command to update an odd byte to an even. since the 8n1 and 7n1 both send the same amount of bits i am hoping the cnc will accept it.

hi,
Get the 628A version of the PIC, if you want to use the 4mHZ internal precision oscillator.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top