Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

Dynamixel & ARDUINO

Bioloid robot kit from Korean company Robotis; CM5 controller block, AX12 servos..
20 postsPage 2 of 21, 2
20 postsPage 2 of 21, 2

Post by gr33nhorn » Tue Sep 16, 2008 6:04 pm

Post by gr33nhorn
Tue Sep 16, 2008 6:04 pm

hi jon,
as stated from your past year reply.regarding the ATmega UART can selectively switch off the transmit and receive pins while it is operating, which is what the code my brother wrote does. In general, the Tx pin is disabled, and its in receive mode. When it needs to transmit an answer back again, it disables the Rx pin, enables the Tx, and then sends the response, and switches them back again.

where can i learn how to change the uart code?any gd website to recommend?i really want to learn from the very basic and pick up one by one
thanks in advance
hi jon,
as stated from your past year reply.regarding the ATmega UART can selectively switch off the transmit and receive pins while it is operating, which is what the code my brother wrote does. In general, the Tx pin is disabled, and its in receive mode. When it needs to transmit an answer back again, it disables the Rx pin, enables the Tx, and then sends the response, and switches them back again.

where can i learn how to change the uart code?any gd website to recommend?i really want to learn from the very basic and pick up one by one
thanks in advance
gr33nhorn
Robot Builder
Robot Builder
Posts: 12
Joined: Sat Sep 13, 2008 9:35 pm

Post by JonHylands » Wed Sep 17, 2008 4:22 am

Post by JonHylands
Wed Sep 17, 2008 4:22 am

No idea - the only example I have is the code my brother wrote...

- Jon
No idea - the only example I have is the code my brother wrote...

- Jon
JonHylands
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 512
Joined: Thu Nov 09, 2006 1:00 am
Location: Ontario, Canada

Post by StuartL » Wed Sep 17, 2008 11:07 am

Post 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.
StuartL
Savvy Roboteer
Savvy Roboteer
Posts: 350
Joined: Mon Jun 04, 2007 3:46 pm
Location: Thatcham, Berkshire, UK

Post by StuartL » Wed Sep 17, 2008 11:11 am

Post by StuartL
Wed Sep 17, 2008 11:11 am

limor wrote:i didn't know that you had modules working this way. This issue was discussed before here with relation to the Pepper board and somehow I got the impression that there was some kind of electrical or signal problem with shorting the RX and TX on the Atmega.


If you set both TX and RX as output (i.e. if(DDRtx & _BV(TXpin) && DDRrx & _BV(RXpin)) then you run a severe risk of blowing up the AVR.

We solve this problem by ensuring that the only place we modify those two bits is in the same routine and the current output is always set to zero (making it an input) before the new output is set. This way we don't short out the PSU even for a microsecond.

It's code discipline :D
limor wrote:i didn't know that you had modules working this way. This issue was discussed before here with relation to the Pepper board and somehow I got the impression that there was some kind of electrical or signal problem with shorting the RX and TX on the Atmega.


If you set both TX and RX as output (i.e. if(DDRtx & _BV(TXpin) && DDRrx & _BV(RXpin)) then you run a severe risk of blowing up the AVR.

We solve this problem by ensuring that the only place we modify those two bits is in the same routine and the current output is always set to zero (making it an input) before the new output is set. This way we don't short out the PSU even for a microsecond.

It's code discipline :D
StuartL
Savvy Roboteer
Savvy Roboteer
Posts: 350
Joined: Mon Jun 04, 2007 3:46 pm
Location: Thatcham, Berkshire, UK

Post by billyzelsnack » Wed Sep 17, 2008 5:50 pm

Post by billyzelsnack
Wed Sep 17, 2008 5:50 pm

StuartL.. Do you put a small delay in between? I wonder if those pins can still be high for a short amount time. Seems unlikely that the uC would block on that instruction waiting for it to go low. Maybe it does though or maybe it doesn't really matter.
StuartL.. Do you put a small delay in between? I wonder if those pins can still be high for a short amount time. Seems unlikely that the uC would block on that instruction waiting for it to go low. Maybe it does though or maybe it doesn't really matter.
billyzelsnack
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 618
Joined: Sat Dec 30, 2006 1:00 am

Previous
20 postsPage 2 of 21, 2
20 postsPage 2 of 21, 2