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

USART Question

Bioloid robot kit from Korean company Robotis; CM5 controller block, AX12 servos..
4 postsPage 1 of 1
4 postsPage 1 of 1

USART Question

Post by bergere » Mon May 26, 2008 1:55 pm

Post by bergere
Mon May 26, 2008 1:55 pm

Hello again,

I want to transmit Data via USART. This works fine for UDR1 on my Atmega128. I was surprised that works without any initialisation.

Code: Select all
void TxD81(byte bTxdData)
{
  while(!(bit_is_set(UCSR1A,5)));
  UDR1 = bTxdData;
}


But if i try to use UDR0 it doesn´t work. So i want to initialise UDR0.

Code: Select all
void USART_Init( unsigned int ubrr )
{
   /*   Activate USART Transmitter                  */
    UCSR0B |= (1<<TXEN0);

   /*   Set 1 Stop Bit                            */
    UCSR0C &= ~(1<<USBS0);      
   
   
   /*   Activate Asynchronus Transfermode            */
   UCSR0C &= ~(1<<UMSEL0);
   
   /*     Choose Frame Format                                   */
   UCSR0C |= (1<<UCSZ00);            
   UCSR0C |= (1<<UCSZ01);
   UCSR0B &= ~(1<<UCSZ02);

   /*   Synchronisation             */
    UBRR0H = 0x00;
    UBRR0L = 0x22;
}


My UDRR is 34 for Asynchronous Transfer Mode.

Question Number 1: Why i havn´t to initalise UDR1???
Question Number 2: Is this Initialisation correct? Or do i forgot something?
Question Number 3: Maybe UDR0 isn´t Used for Transmitting Data because i found that his UBRRL isn´t correctly defined in the iom128.h file.

For example:

Code: Select all
/* USART0 Baud Rate Register High */
#define UBRR0H    _SFR_MEM8(0x90)

/* USART0 Control and Status Register C */
#define UCSR0C    _SFR_MEM8(0x95)

/* USART1 Baud Rate Register High */
#define UBRR1H    _SFR_MEM8(0x98)

/* USART1 Baud Rate Register Low*/
#define UBRR1L    _SFR_MEM8(0x99)

/* USART1 Control and Status Register B */
#define UCSR1B    _SFR_MEM8(0x9A)

/* USART1 Control and Status Register A */
#define UCSR1A    _SFR_MEM8(0x9B)

/* USART1 I/O Data Register */
#define UDR1      _SFR_MEM8(0x9C)

/* USART1 Control and Status Register C */
#define UCSR1C    _SFR_MEM8(0x9D)


You can see that there isnt defined the UBRRL and many other things. But in the Atmega 128 Documentation they are listed. For example
||$09 ($29)|| UBRR0L USART0 Baud Rate Register Low
But it isn´t defined in the iom128.h. Why?

OK I hope you understand my problem despite my bad english.
Hello again,

I want to transmit Data via USART. This works fine for UDR1 on my Atmega128. I was surprised that works without any initialisation.

Code: Select all
void TxD81(byte bTxdData)
{
  while(!(bit_is_set(UCSR1A,5)));
  UDR1 = bTxdData;
}


But if i try to use UDR0 it doesn´t work. So i want to initialise UDR0.

Code: Select all
void USART_Init( unsigned int ubrr )
{
   /*   Activate USART Transmitter                  */
    UCSR0B |= (1<<TXEN0);

   /*   Set 1 Stop Bit                            */
    UCSR0C &= ~(1<<USBS0);      
   
   
   /*   Activate Asynchronus Transfermode            */
   UCSR0C &= ~(1<<UMSEL0);
   
   /*     Choose Frame Format                                   */
   UCSR0C |= (1<<UCSZ00);            
   UCSR0C |= (1<<UCSZ01);
   UCSR0B &= ~(1<<UCSZ02);

   /*   Synchronisation             */
    UBRR0H = 0x00;
    UBRR0L = 0x22;
}


My UDRR is 34 for Asynchronous Transfer Mode.

Question Number 1: Why i havn´t to initalise UDR1???
Question Number 2: Is this Initialisation correct? Or do i forgot something?
Question Number 3: Maybe UDR0 isn´t Used for Transmitting Data because i found that his UBRRL isn´t correctly defined in the iom128.h file.

For example:

Code: Select all
/* USART0 Baud Rate Register High */
#define UBRR0H    _SFR_MEM8(0x90)

/* USART0 Control and Status Register C */
#define UCSR0C    _SFR_MEM8(0x95)

/* USART1 Baud Rate Register High */
#define UBRR1H    _SFR_MEM8(0x98)

/* USART1 Baud Rate Register Low*/
#define UBRR1L    _SFR_MEM8(0x99)

/* USART1 Control and Status Register B */
#define UCSR1B    _SFR_MEM8(0x9A)

/* USART1 Control and Status Register A */
#define UCSR1A    _SFR_MEM8(0x9B)

/* USART1 I/O Data Register */
#define UDR1      _SFR_MEM8(0x9C)

/* USART1 Control and Status Register C */
#define UCSR1C    _SFR_MEM8(0x9D)


You can see that there isnt defined the UBRRL and many other things. But in the Atmega 128 Documentation they are listed. For example
||$09 ($29)|| UBRR0L USART0 Baud Rate Register Low
But it isn´t defined in the iom128.h. Why?

OK I hope you understand my problem despite my bad english.
Für Fehler und Schrift haftet der Stift. Palim Palim
bergere
Savvy Roboteer
Savvy Roboteer
Posts: 28
Joined: Thu Nov 29, 2007 10:18 pm

Post by limor » Tue May 27, 2008 4:34 pm

Post by limor
Tue May 27, 2008 4:34 pm

I trust you are referring to CM5 ?

In this case one UART is used to communicate with the AX12 servos and the other, to communicate with PC/Zigbee/Bluetooth.

For this type of setup you can find some working example code posted here previously. see the Bioloid Wiki for links.
I trust you are referring to CM5 ?

In this case one UART is used to communicate with the AX12 servos and the other, to communicate with PC/Zigbee/Bluetooth.

For this type of setup you can find some working example code posted here previously. see the Bioloid Wiki for links.
limor
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1845
Joined: Mon Oct 11, 2004 1:00 am
Location: London, UK

Post by bergere » Wed May 28, 2008 10:07 am

Post by bergere
Wed May 28, 2008 10:07 am

So UDR0 is just 4 the motors and the UDR1 for the communication between CM-5 and "Terminal".

Thx 4 Help
So UDR0 is just 4 the motors and the UDR1 for the communication between CM-5 and "Terminal".

Thx 4 Help
Für Fehler und Schrift haftet der Stift. Palim Palim
bergere
Savvy Roboteer
Savvy Roboteer
Posts: 28
Joined: Thu Nov 29, 2007 10:18 pm

Post by le fatumbi » Fri May 30, 2008 8:09 am

Post by le fatumbi
Fri May 30, 2008 8:09 am

bergere wrote:So UDR0 is just 4 the motors and the UDR1 for the communication between CM-5 and "Terminal"


Note that UDR1 is used also for zigbee option.

You have to manage corresponding i/o pins to select output interface (zigbee/terminal). That should be well initialized by default if you didn't change PORTD configuration.

I concerns these pins:

Switch to output direction and to true (1) state these pins to select pc direction:
BIT_ZIGBEE_RESET PortD4;
BIT_ENABLE_RXD_LINK_PC PortD5;
BIT_ENABLE_RXD_LINK_ZIGBEE PortD6;

switch this one to input direction:
BIT_LINK_PLUGIN Port_D7;

a very fast configuration that works : (wrote inAda)
Code: Select all
   -------------------------
   -- Initialize_Pc_Rs232 --
   -------------------------

   procedure Initialize_Pc_Rs232 is
      BIT_ZIGBEE_RESET           : constant Pin := Port_D4;
      BIT_ENABLE_RXD_LINK_PC     : constant Pin := Port_D5;
      BIT_ENABLE_RXD_LINK_ZIGBEE : constant Pin := Port_D6;
      BIT_LINK_PLUGIN            : constant Pin := Port_D7;
   begin

      -- Init Port
      -- Set output Zigbee and pc control pins;
       Switch_Output(BIT_ZIGBEE_RESET);
      -- (switch_Ouput writes 1 in corresponding DDRx)
       Switch_Output(BIT_ENABLE_RXD_LINK_PC);
       Switch_Output(BIT_ENABLE_RXD_LINK_ZIGBEE);
       Switch_Input(BIT_LINK_PLUGIN); --(no pull up)
      -- (switch_Input writes 0 in corresponding DDRx)

       -- Select pc connection
       Output(BIT_ZIGBEE_RESET, true);
       -- ('ouput' writes value in corresponding PORTx)
       Output(BIT_ENABLE_RXD_LINK_PC, true);
       Output(BIT_ENABLE_RXD_LINK_ZIGBEE, true);

       -- Init USART 1
       Set(UBRR1H, 0);
       Set(UBRR1L, 34);--Default_Bdr : 56700 bds;
       -- (note we disabled interrupt before all initializations... in case of...)

       Set(UCSR1C, 16#06#); -- 8bits, 1 stop, no parity

      Set(UCSR1A, 16#02#);--  Receive Data Bit 8

      Set_Bit(UCSR1B, RXCIE1_Bit, false);-- RxD interrupt disabled
      Set_Bit(UCSR1B, RXEN1_Bit, true);  --  Rx enable
      Set_Bit(UCSR1B, TXCIE1_Bit, false);-- TxD interrupt disabled
      Set_Bit(UCSR1B, TXEN1_Bit, true);  --  Tx enable

   end Initialize_Pc_Rs232;


For a good unitary test, without any doubt on your terminal conf, you can link Rx and Tx together and control that this echoes well... telling the result to a DEL...)
bergere wrote:So UDR0 is just 4 the motors and the UDR1 for the communication between CM-5 and "Terminal"


Note that UDR1 is used also for zigbee option.

You have to manage corresponding i/o pins to select output interface (zigbee/terminal). That should be well initialized by default if you didn't change PORTD configuration.

I concerns these pins:

Switch to output direction and to true (1) state these pins to select pc direction:
BIT_ZIGBEE_RESET PortD4;
BIT_ENABLE_RXD_LINK_PC PortD5;
BIT_ENABLE_RXD_LINK_ZIGBEE PortD6;

switch this one to input direction:
BIT_LINK_PLUGIN Port_D7;

a very fast configuration that works : (wrote inAda)
Code: Select all
   -------------------------
   -- Initialize_Pc_Rs232 --
   -------------------------

   procedure Initialize_Pc_Rs232 is
      BIT_ZIGBEE_RESET           : constant Pin := Port_D4;
      BIT_ENABLE_RXD_LINK_PC     : constant Pin := Port_D5;
      BIT_ENABLE_RXD_LINK_ZIGBEE : constant Pin := Port_D6;
      BIT_LINK_PLUGIN            : constant Pin := Port_D7;
   begin

      -- Init Port
      -- Set output Zigbee and pc control pins;
       Switch_Output(BIT_ZIGBEE_RESET);
      -- (switch_Ouput writes 1 in corresponding DDRx)
       Switch_Output(BIT_ENABLE_RXD_LINK_PC);
       Switch_Output(BIT_ENABLE_RXD_LINK_ZIGBEE);
       Switch_Input(BIT_LINK_PLUGIN); --(no pull up)
      -- (switch_Input writes 0 in corresponding DDRx)

       -- Select pc connection
       Output(BIT_ZIGBEE_RESET, true);
       -- ('ouput' writes value in corresponding PORTx)
       Output(BIT_ENABLE_RXD_LINK_PC, true);
       Output(BIT_ENABLE_RXD_LINK_ZIGBEE, true);

       -- Init USART 1
       Set(UBRR1H, 0);
       Set(UBRR1L, 34);--Default_Bdr : 56700 bds;
       -- (note we disabled interrupt before all initializations... in case of...)

       Set(UCSR1C, 16#06#); -- 8bits, 1 stop, no parity

      Set(UCSR1A, 16#02#);--  Receive Data Bit 8

      Set_Bit(UCSR1B, RXCIE1_Bit, false);-- RxD interrupt disabled
      Set_Bit(UCSR1B, RXEN1_Bit, true);  --  Rx enable
      Set_Bit(UCSR1B, TXCIE1_Bit, false);-- TxD interrupt disabled
      Set_Bit(UCSR1B, TXEN1_Bit, true);  --  Tx enable

   end Initialize_Pc_Rs232;


For a good unitary test, without any doubt on your terminal conf, you can link Rx and Tx together and control that this echoes well... telling the result to a DEL...)
le fatumbi
Robot Builder
Robot Builder
User avatar
Posts: 15
Joined: Sun May 04, 2008 9:07 am
Location: france


4 postsPage 1 of 1
4 postsPage 1 of 1