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 support@ccsinfo.com

#use rs232(ICD) and kbhit() [Solved: req. hardware UART]

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



Joined: 17 Jun 2019
Posts: 498
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

#use rs232(ICD) and kbhit() [Solved: req. hardware UART]
PostPosted: Thu Sep 23, 2021 2:20 pm     Reply with quote

Should kbhit() even work when using the siow.exe monitor via the ICD debugger?

I was hoping to use some of my serial port console code (menu system) via the ICD debugger, but I have only had success when I do blocking I/O (getc, etc.). I can't block in my test program, so I was trying to find a way to do no-blocking getc() over the ICD console.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC programmer.
www.whywouldyouwanttodothat.com ?


Last edited by allenhuffman on Fri Sep 24, 2021 1:12 pm; edited 1 time in total
allenhuffman



Joined: 17 Jun 2019
Posts: 498
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Sep 23, 2021 3:33 pm     Reply with quote

Additional ... our board uses the ICSP port (PIN_B0 and PIN_B1) so I was able to get it working there:

Code:
#pin_select U1TX=PIN_B0
#pin_select U1RX=PIN_B1
#use rs232 (BAUD=115200, XMIT=PIN_B0, RCV=PIN_B1)

_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC programmer.
www.whywouldyouwanttodothat.com ?
jeremiah



Joined: 20 Jul 2010
Posts: 1249

View user's profile Send private message

PostPosted: Thu Sep 23, 2021 4:41 pm     Reply with quote

It depends on if you are using a software serial or hardware serial connection. Software serial connections are usually pretty unreliable when it comes to receiving. You have to do *nothing else* other than sit on the receive, which kind of makes kbhit() useless since you can't do any other code. The slightest interrupt can also mess them up because they have to basically sit there looking at the I/O to read it in the moment it arrives. Contrast that with a hardware serial port that has the built in 4 byte buffer so you can come back and check it later. Ttelmah has a software serial implementation that he created that is more reliable than a standard one somewhere on the forums, but it isn't used by the ICD that I am aware of.

If you are using an ICD-U64 or ICD-U80 serial connection, it is a software serial, so kbhit() will be difficult to pull off.

Side note, your hardware serial setup example is a bit incorrect. You specify hardware pins via #pin_select and then proceed to specify software serial pins in the #use. On some versions of the compiler that will create a software serial connection and on other versions it will create a hardware version (I've had compiler upgrades cause my code to stop executing correctly due to this, so I started specifying it a specific way for hardware connections). If you want to specify a hardware serial port, the minimum should be:

Code:

#pin_select U1TX=PIN_B0
#pin_select U1RX=PIN_B1
#use rs232 (UART1,BAUD=115200, ERRORS)

with a stream or other options set as necessary

if you plan on using the ICD-UXX serial port, then the minimum declaration should be:
Code:

#use rs232 (ICD,DISABLE_INTS)

with a stream option set as necessary
allenhuffman



Joined: 17 Jun 2019
Posts: 498
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Sep 24, 2021 1:12 pm     Reply with quote

jeremiah wrote:

Side note, your hardware serial setup example is a bit incorrect. You specify hardware pins via #pin_select and then proceed to specify software serial pins in the #use. On some versions of the compiler that will create a software serial connection and on other versions it will create a hardware version (I've had compiler upgrades cause my code to stop executing correctly due to this, so I started specifying it a specific way for hardware connections). If you want to specify a hardware serial port, the minimum should be:

Code:

#pin_select U1TX=PIN_B0
#pin_select U1RX=PIN_B1
#use rs232 (UART1,BAUD=115200, ERRORS)

with a stream or other options set as necessary
[/code]
with a stream option set as necessary


Thanks -- I had just come across that after my post. Works like a charm.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC programmer.
www.whywouldyouwanttodothat.com ?
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