ROBOTC.net forums
http://www.robotc.net/forums/

Bug Report:RX/TX ports don't work as IO ports when debugging
http://www.robotc.net/forums/viewtopic.php?f=62&t=4547
Page 1 of 1

Author:  NeXT-Generation [ Wed May 16, 2012 11:06 am ]
Post subject:  Bug Report:RX/TX ports don't work as IO ports when debugging

I've the following code:

Code:
#pragma config(CircuitBoardType, typeCktBoardUNO)
#pragma config(Sensor, dgtl0,  ,               sensorDigitalOut)
#pragma config(Sensor, dgtl4,  ,               sensorDigitalOut)
#pragma config(Sensor, dgtl12, ,               sensorDigitalOut)
#pragma config(Sensor, dgtl13, ,               sensorDigitalOut)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  wait1Msec(5000);
 
  SensorValue(dgtl13) = 1;
  SensorValue(dgtl12) = 0;
 
  SensorValue(dgtl0) = 0;
 
  while(true)
  {
    SensorValue(dgtl4) = 1;
    wait1Msec(500);
    SensorValue(dgtl4) = 0;
    wait1Msec(500);
  }
}


This should blink the LED on pins 4 and 0 when the LED on pins 13 and 12 turn on. The second LED turns on, but the first one doesn't. I've tried it with both pins 0 and 1, so one would logically conclude that the RX/TX ports do not work as general digital I/O.

EDIT: I've edited the title to be more specific.
EDIT Reduex: Title even more specific.

Author:  Dennis Mabrey [ Wed May 16, 2012 11:26 am ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

NeXT-Generation wrote:
This should blink the LED on pins 4 and 0 when the LED on pins 13 and 12 turn on. The second LED turns on, but the first one doesn't. I've tried it with both pins 0 and 1, so one would logically conclude that the RX/TX ports do not work as general digital I/O.


Normally you don't want to use digital pins 0 and 1 except for serial communications. If you have the Arduino hooked up to your USB that will interfere with it (this is how the Arduino is wired, same thing happens using Serial monitor in Arduino IDE).

Besides that I am a bit confused by something you said. There is no code (that I see of) that blinks pin 0. You only make one call before the while loop that turns pin 0 off.

Author:  NeXT-Generation [ Wed May 16, 2012 11:43 am ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

Dennis Mabrey wrote:
NeXT-Generation wrote:
This should blink the LED on pins 4 and 0 when the LED on pins 13 and 12 turn on. The second LED turns on, but the first one doesn't. I've tried it with both pins 0 and 1, so one would logically conclude that the RX/TX ports do not work as general digital I/O.


Normally you don't want to use digital pins 0 and 1 except for serial communications. If you have the Arduino hooked up to your USB that will interfere with it (this is how the Arduino is wired, same thing happens using Serial monitor in Arduino IDE).

Besides that I am a bit confused by something you said. There is no code (that I see of) that blinks pin 0. You only make one call before the while loop that turns pin 0 off.


Oh. I didn't know that. If that's true, then why is there the option to use them as such?

One LED is connected to pins 0 (or 1) and 4. The other to pins 12 and 13. Pin 0 (or 1) is initialized to GND, and pin 4 switches between GND and 5V, hence blinking the LED.

Author:  Dennis Mabrey [ Wed May 16, 2012 12:12 pm ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

NeXT-Generation wrote:
Oh. I didn't know that. If that's true, then why is there the option to use them as such?


Well it only causes a conflict when you are using the USB for serial data transfer / program download / debugging. If you did not have the Arduino connected to your PC they should work like normal digital pins. Generally people don't use those two pins unless it is for serial communications such as communicating with a GPS.

The Arduino website says the following: You should note, however, that pins 0 & 1 are used for serial communications for programming and debugging the Arduino, so changing these pins should usually be avoided unless needed for serial input or output functions. Be aware that this can interfere with program download or debugging.
(see http://www.arduino.cc/en/Reference/PortManipulation )

NeXT-Generation wrote:
One LED is connected to pins 0 (or 1) and 4. The other to pins 12 and 13. Pin 0 (or 1) is initialized to GND, and pin 4 switches between GND and 5V, hence blinking the LED.


Oh. Ok well try changing the code from pin 0 to a different digital pin.

Author:  NeXT-Generation [ Wed May 16, 2012 12:27 pm ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

Dennis Mabrey wrote:
NeXT-Generation wrote:
Oh. I didn't know that. If that's true, then why is there the option to use them as such?


Well it only causes a conflict when you are using the USB for serial data transfer / program download / debugging. If you did not have the Arduino connected to your PC they should work like normal digital pins. Generally people don't use those two pins unless it is for serial communications such as communicating with a GPS.

The Arduino website says the following: You should note, however, that pins 0 & 1 are used for serial communications for programming and debugging the Arduino, so changing these pins should usually be avoided unless needed for serial input or output functions. Be aware that this can interfere with program download or debugging.
(see http://www.arduino.cc/en/Reference/PortManipulation )

NeXT-Generation wrote:
One LED is connected to pins 0 (or 1) and 4. The other to pins 12 and 13. Pin 0 (or 1) is initialized to GND, and pin 4 switches between GND and 5V, hence blinking the LED.


Oh. Ok well try changing the code from pin 0 to a different digital pin.


I didn't know all that. Thanks! :bigthumb: I guess I'll just have to make it a bit more complicated. My current design was going to use all pins but one, but I guess I can Charlieplex some of the LEDs.

EDIT: Though I can't get this to work in RobotC, it works perfectly fine with the standard Arduino software. How odd.

Author:  NeXT-Generation [ Thu May 17, 2012 10:29 am ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

Just an update: I've been able to get the RX/TX lines working as I/O with no problems in Arduino soft, but no matter what I try can't get them to work with RobotC. I think that that's kinda weird. Oh well. Guess my wiring will just have to be more complicated.....

Author:  Dennis Mabrey [ Thu May 17, 2012 11:18 am ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

NeXT-Generation wrote:
Just an update: I've been able to get the RX/TX lines working as I/O with no problems in Arduino soft, but no matter what I try can't get them to work with RobotC. I think that that's kinda weird. Oh well. Guess my wiring will just have to be more complicated.....


Were you running the debugger in RobotC at the time? The debug information is passed to the PC over the serial ports (and pins 0 and 1 are connected to serial).

It will work fine with the Arduino IDE until you call Serial.println() in your loop function with the serial monitor running. You will see problems in that case.

I was going to ask if you tried it while connected to external power only. I will try something later today when I get into the office.

Author:  NeXT-Generation [ Thu May 17, 2012 12:36 pm ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

Hmm. I hadn't thought of USB interfering. So....

Running this code....
Code:
#pragma config(CircuitBoardType, typeCktBoardUNO)
#pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0)
#pragma config(Sensor, dgtl9,  ,               sensorDigitalOut)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  wait1Msec(5000);
 
  SensorType(UART0) = uartNotUsed;
  SensorType(dgtl0) = sensorDigitalOut;
  SensorValue(dgtl0) = 0;
 
  while(true)
  {
    SensorValue(dgtl9) = 1;
    wait1Msec(200);
    SensorValue(dgtl9) = 0;
    wait1Msec(200);
  }
}


Plug in Power jack... Unplug USB.... waiting for the timer.... and the LED is blinking!!!! I hadn't thought to unplug the USB. Thanks, Dennis! Now it'll be much easier to port the Arduino code I've been testing.

Author:  magicode [ Thu May 17, 2012 12:38 pm ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

Setting the debugger to "snapshot" instead of "continuous" might also work, so you don't have to unplug the USB.

Author:  NeXT-Generation [ Thu May 17, 2012 12:41 pm ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

magicode wrote:
Setting the debugger to "snapshot" instead of "continuous" might also work, so you don't have to unplug the USB.


Testing.... That also works!

Okay, so as long as it isn't communicating with RobotC, RX/TX lines work as expected. Thanks for the help, everyone! :bigthumb:

Author:  Dennis Mabrey [ Thu May 17, 2012 1:17 pm ]
Post subject:  Re: Bug Report: RX/TX ports don't work as GPIO ports.

magicode wrote:
Setting the debugger to "snapshot" instead of "continuous" might also work, so you don't have to unplug the USB.


Dang should have thought of that. :biggrin:

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/