int rc100Initialize(uint32 baudrate ) { /* * Opening device * baudrate: Real baudrate (ex> 115200, 57600, 38400...) * Return: 0(Failed), 1(Succeed) * * */ gpio_set_mode(GPIOA, 2, GPIO_AF_OUTPUT_PP); gpio_set_mode(GPIOA, 3, GPIO_INPUT_FLOATING); usart_init(USART2); //TxDStringC("USART clock = ");TxDHex32C(STM32_PCLK2);TxDStringC("\r\n"); usart_set_baud_rate(USART2, STM32_PCLK1, baudrate); usart_attach_interrupt(USART2,rc100Interrupt); usart_enable(USART2); gbRcvFlag = 0; gwRcvData = 0; gbRcvPacketNum = 0; /*Clear rx tx uart2 buffer */ gbPacketWritePointer =0; gbPacketReadPointer=0; return 1; }
void Dynamixel::begin(int baud){ uint32 Baudrate = 0; if(mDxlUsart == USART1) afio_remap(AFIO_REMAP_USART1); #ifdef BOARD_CM900 //Engineering version case gpio_set_mode(PORT_ENABLE_TXD, PIN_ENABLE_TXD, GPIO_OUTPUT_PP); gpio_set_mode(PORT_ENABLE_RXD, PIN_ENABLE_RXD, GPIO_OUTPUT_PP); gpio_write_bit(PORT_ENABLE_TXD, PIN_ENABLE_TXD, 0 );// TX Disable gpio_write_bit(PORT_ENABLE_RXD, PIN_ENABLE_RXD, 1 );// RX Enable #else gpio_set_mode(mDirPort, mDirPin, GPIO_OUTPUT_PP); gpio_write_bit(mDirPort, mDirPin, 0 );// RX Enable //gpio_set_mode(GPIOB, 5, GPIO_OUTPUT_PP); // gpio_write_bit(GPIOB, 5, 0 );// RX Enable #endif // initialize GPIO D20(PB6), D21(PB7) as DXL TX, RX respectively gpio_set_mode(mTxPort, mTxPin, GPIO_AF_OUTPUT_PP); gpio_set_mode(mRxPort, mRxPin, GPIO_INPUT_FLOATING); //Initialize USART 1 device usart_init(mDxlUsart); //Calculate baudrate, refer to ROBOTIS support page. Baudrate = 2000000 / (baud + 1); if(mDxlUsart == USART1) usart_set_baud_rate(mDxlUsart, STM32_PCLK2, Baudrate); else usart_set_baud_rate(mDxlUsart, STM32_PCLK1, Baudrate); nvic_irq_set_priority(mDxlUsart->irq_num, 0);//[ROBOTIS][ADD] 2013-04-10 set to priority 0 usart_attach_interrupt(mDxlUsart, mDxlDevice->handlers); usart_enable(mDxlUsart); delay(80); mDXLtxrxStatus = 0; mBusUsed = 0;// only 1 when tx/rx is operated //gbIsDynmixelUsed = 1; //[ROBOTIS]2012-12-13 to notify end of using dynamixel SDK to uart.c this->clearBuffer(); this->setLibStatusReturnLevel(2); this->setLibNumberTxRxAttempts(1); }
//Dynamixel::~Dynamixel() { // // TODO Auto-generated destructor stub //} void Dynamixel::begin(int baud) { uint32 Baudrate = 0; mPacketType = DXL_PACKET_TYPE1; //2014-04-02 default packet type is 1.0 -> set as 1 if(mDxlUsart == USART1) afio_remap(AFIO_REMAP_USART1); #ifdef BOARD_CM900 //Engineering version case gpio_set_mode(PORT_ENABLE_TXD, PIN_ENABLE_TXD, GPIO_OUTPUT_PP); gpio_set_mode(PORT_ENABLE_RXD, PIN_ENABLE_RXD, GPIO_OUTPUT_PP); gpio_write_bit(PORT_ENABLE_TXD, PIN_ENABLE_TXD, 0 );// TX Disable gpio_write_bit(PORT_ENABLE_RXD, PIN_ENABLE_RXD, 1 );// RX Enable #else if(mDirPort != 0) { gpio_set_mode(mDirPort, mDirPin, GPIO_OUTPUT_PP); gpio_write_bit(mDirPort, mDirPin, 0 );// RX Enable } //gpio_set_mode(GPIOB, 5, GPIO_OUTPUT_PP); // gpio_write_bit(GPIOB, 5, 0 );// RX Enable #endif // initialize GPIO D20(PB6), D21(PB7) as DXL TX, RX respectively gpio_set_mode(mTxPort, mTxPin, GPIO_AF_OUTPUT_PP); gpio_set_mode(mRxPort, mRxPin, GPIO_INPUT_FLOATING); //Initialize USART 1 device usart_init(mDxlUsart); //Calculate baudrate, refer to ROBOTIS support page. //Baudrate = dxl_get_baudrate(baud); //Dxl 2.0 if(baud == 3) baud = 1; else if(baud == 2) baud = 16; else if(baud == 1) baud = 34; else if(baud == 0) baud = 207; Baudrate = 2000000 / (baud + 1); if(mDxlUsart == USART1) usart_set_baud_rate(mDxlUsart, STM32_PCLK2, Baudrate); else usart_set_baud_rate(mDxlUsart, STM32_PCLK1, Baudrate); nvic_irq_set_priority(mDxlUsart->irq_num, 0);//[ROBOTIS][ADD] 2013-04-10 set to priority 0 usart_attach_interrupt(mDxlUsart, mDxlDevice->handlers); usart_enable(mDxlUsart); delay(100); mDXLtxrxStatus = 0; mBusUsed = 0;// only 1 when tx/rx is operated //gbIsDynmixelUsed = 1; //[ROBOTIS]2012-12-13 to notify end of using dynamixel SDK to uart.c this->setLibStatusReturnLevel(2); this->setLibNumberTxRxAttempts(2); this->clearBuffer(); if(this->checkPacketType()) { // Dxl 2.0 this->setPacketType(DXL_PACKET_TYPE2); } else { // Dxl 1.0 this->setPacketType(DXL_PACKET_TYPE1); } this->setLibNumberTxRxAttempts(1); this->clearBuffer(); if(mDxlUsart == USART2) { //140508 shin SmartDelayFlag = 1; this->setPacketType(DXL_PACKET_TYPE2); } }