CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Writing RS232 data to I2C problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
b77ng



Joined: 22 Jan 2014
Posts: 7

View user's profile Send private message

Writing RS232 data to I2C problem
PostPosted: Fri Feb 14, 2014 8:37 pm     Reply with quote

Hi everyone

I'm writing a 12F629 program which needs to write data received from a PC via RS232 to an I2C EEPROM. The PIC software is working fine, correct data is received from the PC. The problem is that I need to pause the sending of bytes while writing to the EEPROM (takes ~5ms each byte). When I use HyperTerminal in text file transfer mode with delay between characters, the receiving of data doesn't work correctly, the PIC behaves as if not enough bytes are received and I'm guessing it's because of something HyperTerminal does to the data in text trasfer mode.
Anyone knows about some way to send data correctly with inter byte delay?
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sat Feb 15, 2014 1:47 am     Reply with quote

Handshake....

You would need to enable (ideally) hardware handshaking, and add the hardware to support this.
Setup the PC serial port to use hardware handshake.

Then does your data have some form of 'packet' format?. Better if it does.

Have the hardware handshake go 'busy' just before the end of the packet (you have to remember that the PC has hardware buffering, so it takes a short time for transmission to stop when the handshake goes busy).

You don't want to be working 'byte by byte'. If (for instance) you have a packet that is the size of a 'page' in the EEPROM, then when the line goes busy, have the receiving chip, write a page to the EEPROM.

If you must work 'byte by byte', then change your hardware, and instead of EEPROM, use FRAM. Much better write life (near infinite!). Instant writes (can accept data as fast as it is transferred).
b77ng



Joined: 22 Jan 2014
Posts: 7

View user's profile Send private message

PostPosted: Sat Feb 15, 2014 11:43 am     Reply with quote

Hi

I initially excluded HW handshaking because I'm out of pins (12F629, remember) and it would require modifications to the hardware setup.
I'm not using a level shifter, but only a resistor and a zener for TX, which does the job alright. Upon consideration it looks like HW handshaking is not so hard to do.

The RS232 to I2C transfer is an one-time operation. No performance considerations need apply, nor do I care about lifetime of the EEPROM, it'll get written to very rarely. So I'm writing one byte at a time, speed does not matter.

Meanwhile I added a wire from the 12F to the PC CTS line and after a lot of headache I managed to get it to work. Looks like my problem was caused by the terminal emulation software I was using. 4 different (!) apps were behaving in at least 4 different ways (simply wrong data, unwilling to send extended (> 7Fh) ASCII characters, stuck after 256 bytes or not working at all being some examples). HyperTerminal seems to do the job, I'm now able to send 32kbytes with no error.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Feb 15, 2014 2:55 pm     Reply with quote

Another way of implementing handshaking with just the Tx/Rx lines is a software handshake method called XON/XOFF.

Whenever your PIC is ready to receive data you (periodically) send the XON character (0x11) to the PC. When the PIC buffer is full or can't receive data for other reasons you send the XOFF (0x13) character to the PC. When the PIC is ready to receive new data it sends the XON character again.


Note that with the software based handshake there often is a small time delay before the PC can respond to the received XOFF character and you might receive a few more bytes before the PC pauses transmission. You will have to send the XOFF characters a little before your receive buffer is full, or create a slightly larger receive buffer.
b77ng



Joined: 22 Jan 2014
Posts: 7

View user's profile Send private message

PostPosted: Sat Feb 15, 2014 3:56 pm     Reply with quote

Hi

Thanks but it's working now. Maybe it'll be of some help to other people but implementing XON/XOFF would be just another major headache for me as it would need the TX line anyway.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group