![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
#use rs232(ICD) and kbhit() [Solved: req. hardware UART] |
Posted: Thu Sep 23, 2021 2:20 pm |
|
|
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) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Last edited by allenhuffman on Fri Sep 24, 2021 1:12 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Sep 23, 2021 3:33 pm |
|
|
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) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1328
|
|
Posted: Thu Sep 23, 2021 4:41 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Sep 24, 2021 1:12 pm |
|
|
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) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|