by StuartL » Wed Sep 17, 2008 11:07 am
by StuartL
Wed Sep 17, 2008 11:07 am
I can't help with the Arduino programming side of it but if you're using the AVR directly...
The key things you're interested in are the DDR and PORT registers for each of the IO pins. If your TX pin was PD4 and your RX pin was PE0 the registers you would be interested in are:
DDRD bit 4 (data direction for TX pin)
PORTD bit 4 (output data for TX pin)
and
DDRE bit 0 (data direction for RX pin)
PORTE bit 0 (output data for RX pin)
Note that this is all documented in the AVR PDFs.
If DDRx is set to zero the pin is an input pin. This is the default. With the pin as an input pin the PORTx register sets the pull-up for the pin, so bit zero of the PORTE register being zero would mean no pull-up (floating pin, what you want for an input) and bit zero of the PORTE register being one would mean weak pull-up. Pull-up is useful for shared buses but isn't really necessary for the bioloid bus. You can enable it without consequence.
If DDRx is set to one the pin is an output pin and the PORTx bit is used as the value for the output pin.
In all cases you probably want the RX input to be set, although you may wish to disable the receiver so that you don't see your own transmissions.
- Code: Select all
cbi(DDRE, 0); sbi(PORTE, 0); // Set the RX pin to input with weak pull-up. You probably don't want pull-up on anything but the controller.
And your transmit routine looks like this:
- Code: Select all
sbi(DDRD, 4); // Set DDR for Pin D4 to output.
UARTD0 = byte;
while (!txcomplete());
cbi(DDRD, 4); cbi(PORTD, 4); // DDR for Pin D4 to input.
I can't help with the Arduino programming side of it but if you're using the AVR directly...
The key things you're interested in are the DDR and PORT registers for each of the IO pins. If your TX pin was PD4 and your RX pin was PE0 the registers you would be interested in are:
DDRD bit 4 (data direction for TX pin)
PORTD bit 4 (output data for TX pin)
and
DDRE bit 0 (data direction for RX pin)
PORTE bit 0 (output data for RX pin)
Note that this is all documented in the AVR PDFs.
If DDRx is set to zero the pin is an input pin. This is the default. With the pin as an input pin the PORTx register sets the pull-up for the pin, so bit zero of the PORTE register being zero would mean no pull-up (floating pin, what you want for an input) and bit zero of the PORTE register being one would mean weak pull-up. Pull-up is useful for shared buses but isn't really necessary for the bioloid bus. You can enable it without consequence.
If DDRx is set to one the pin is an output pin and the PORTx bit is used as the value for the output pin.
In all cases you probably want the RX input to be set, although you may wish to disable the receiver so that you don't see your own transmissions.
- Code: Select all
cbi(DDRE, 0); sbi(PORTE, 0); // Set the RX pin to input with weak pull-up. You probably don't want pull-up on anything but the controller.
And your transmit routine looks like this:
- Code: Select all
sbi(DDRD, 4); // Set DDR for Pin D4 to output.
UARTD0 = byte;
while (!txcomplete());
cbi(DDRD, 4); cbi(PORTD, 4); // DDR for Pin D4 to input.