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

Xon/Xoff from Computer to Device

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



Joined: 04 Aug 2015
Posts: 16
Location: United States

View user's profile Send private message

Xon/Xoff from Computer to Device
PostPosted: Thu Aug 20, 2015 11:50 am     Reply with quote

Hey all,

I am currently using a PIC18F67J94 with MPLAB X IDE v2.35 for a project. I am having some issues with the Xon/Xoff characters being sent out from the computer to the device. I have done the Xon/Xoff from the device to the computer just fine though. For example, if the computer's buffer gets full, it will send a XOFF character over the bus to the device and tell the device to stop transmitting until XON has been sent over the bus. I do not want to lose any data in my device transmit buffer. How could I integrate XON/XOFF for this process.

I have yet to find an example for XON/XOFF for this flow control. I have found examples for the device to computer flow control.

Any help would be greatly appreciated!
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 20, 2015 12:07 pm     Reply with quote

it's really the same process...
While PIC is receiving data from PC,update the 'data buffer' counter'.when it gets to say 225 char (if buffer is 250), have PIC send XON to PC to tell it to stop transmitting. Now, process the buffer data, when the 'buffer data' counter is say < 10, have the PIC send XOFF to the PC.

Jay
12Lapointep



Joined: 04 Aug 2015
Posts: 16
Location: United States

View user's profile Send private message

PostPosted: Thu Aug 20, 2015 12:18 pm     Reply with quote

This is what I am doing for the information being sent from the computer to the PIC. Here is my part of code for this:
Code:

        if((rcv_buffer_bytes(RS232)>=96) && (XONXOFF == 1))
            {
                putc(XOFF, RS232);
                XONXOFF = 0;
            }
            else if((rcv_buffer_bytes(RS232)<=32) && (XONXOFF == 0))
            {
                putc(XON, RS232);
                XONXOFF = 1;
            }
            else
            {
                if((nSeconds % 10 == 0) && (XONXOFF == 1) && (nSeconds != nXSeconds))
                {
                    nXSeconds=nSeconds;
                    putc(XON, RS232);
                    XONXOFF = 1;
                }
            }

In this case, I am using a 128 bytes receive buffer and if it gets 3/4 full (96 bytes), XOFF is being sent over to the PC to tell it to stop transmitting data. If it gets 1/4 full (32 bytes), XON is sent to the PC and data transmission is resumed.

In TeraTerm, you can set XON/XOFF flow control. The computer will automatically know if the computer buffer is getting full and will send an XOFF to stop transmitting. My question is, how do you handle the transmit buffer of the device so it can still store data while on XOFF, and then send that data over to the computer when it is back on XON?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 20, 2015 1:55 pm     Reply with quote

Ok...

You need an ISR to receive data from PC,
Test for the XON, XOFF bytes.
Based on that test either send data or pause
Now while paused, you have to have 'main' (or wherever the data is coming from...) test to see if the 'transmit buffer' has any available space in it. If so, then add that data to the end of 'transmit buffer'.
You end up needing 3 or 4 counters/flags to keep things organized.

I'm sure Mr. Google can locate code for you, last time I needed this was in the days of TRS80 and 300 baud BBS programs....

Jay
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