2010-10-06 06:35 AM
hi
i was tring to activate USART3 On Port C PC10,PC11. i used this configuration : USART3->CR1 = 0x0C; //Receiver enable, Transmitter enable, USART disable USART3->CR2 = 0x0; USART3->BRR=156;//9600 at 24Mhz setsystemclock(); //set system clock to 24Mhz AFIO->MAPR|=0x10;//port remap as uart //PC10 TX PC11 RX GPIOC->CRH=0x4B00; //PC11 in input floating mode for RX. PC10 Alternative Output TX. RCC->APB2ENR |=0x40000; USART3->CR1 |=2000; //Uart Enable; while(1) { while(TxCounter < 30) { /* Send one byte from USARTy to USARTz */ USART3->DR =( TxBuffer[TxCounter] & (uint16_t)0x01FF); while(((USART3->SR)&0x40)>0);//wait transmition complete TxCounter++; /* Loop until USARTy DR register is empty */ } TxCounter=0; //GPIOC->ODR=0x3ffff; //GPIOC->ODR=0x0; } but for some reason it does not work?? can you help? thanks.2010-10-06 10:24 AM
Well you need to enable the clocks for GPIOC, AFIO and USART3 *BEFORE* configuring the perpheral units themselves.
The AFIO (APB2) is important because you are remapping the IO The GPIOC (APB2) is important because you are doing IO on PORTC The USART3 (APB1) is important because you are using it. The BRR for 9600 baud at 24 MHz (assuming APB1 is @ 24MHz) is 0x9C4 Suggest you use the library code rather than banging on register bits.2010-10-06 11:35 PM
hi.
thanks for your replay. i tried what you said: int main(void) { //RCC->APB2ENR |=0x14; setsystemclock(); //set system clock to 24Mhz AFIO->MAPR|=0x10;//port remap as uart //PC10 TX PC11 RX GPIOC->CRH=0x4B00; //PC11 in input floating mode for RX. PC10 Alternative Output TX. RCC->APB1ENR =0x40000; USART3->CR1 = 0x0C; //Receiver enable, Transmitter enable, USART disable USART3->CR2 = 0x0; USART3->BRR=0x9C4;//9600 at 24Mhz USART3->CR1 |=2000; //Uart Enable; while(1) { while(TxCounter < 30) { /* Send one byte from USARTy to USARTz */ USART3->DR =( TxBuffer[TxCounter] & (uint16_t)0x01FF); while(((USART3->SR)&0x40)==0);//wait transmition complete USART3->SR|=0x40; TxCounter++; /* Loop until USARTy DR register is empty */ } TxCounter=0; } } but still i get nothing from the PC10 output. and the program is stuck on while(((USART3->SR)&0x40)==0);//wait transmition complete becuse the USART3->SR stayis in 0. why? what am i doing wrong? i tried using the librerey code but then i need to add so many files to my project for avery simple definion or i dont understand exeactly what liberey you refer to and how. thanks for your help.2010-10-07 01:50 AM
Did you enable all clocks clive1 mentioned before you start to configure the usart and the port. It will not work otherwise.
Even if you don't use stm32f10x_usart.[ch], you could at least use the defined constants in stm32f10x.h. For example, instead ofUSART3->CR1 |=2000;
you can writeUSART3->CR1 |= USART_CR1_UE;
which is a lot easier to read. (But if you insist of using magic numbers, try 0x2000 instead of 2000)2010-10-07 03:06 AM
thanks for all your help.
i finaly got it working. int main(void) { //RCC->APB2ENR |=0x14; setsystemclock(); //set system clock to 24Mhz GPIOC->CRH=GPIO_CRH_MODE10 | GPIO_CRH_CNF10_1 | GPIO_CRH_CNF11_0 ;//PC11 in input floating mode for RX. PC10 Alternative Output TX. AFIO->MAPR=AFIO_MAPR_USART3_REMAP_0 ;//port remap as uart //PC10 TX PC11 RX RCC->APB1ENR =RCC_APB1ENR_USART3EN ; USART3->CR1 =USART_CR1_RE|USART_CR1_TE; //Receiver enable, Transmitter enable, USART disable USART3->BRR=0x9C4;//9600 at 24Mhz USART3->CR1 |= USART_CR1_UE;; //Uart Enable; while(1) { while(TxCounter < 30) { USART3->DR =('5'); while(((USART3->SR)&USART_SR_TXE )==0);/* Loop until USARTy DR register is empty */ TxCounter++; } TxCounter=0; } } it works.2010-10-07 04:26 AM
2010-10-07 04:53 AM
2010-10-07 05:01 AM
2010-10-07 07:54 AM
Or'ing it would be better, rather than assuming you knew the initial content
RCC->APB2ENR |=RCC_APB2RSTR_IOPCRST | RCC_APB2RSTR_AFIORST;
Which would be the equivalent to RCC->APB2ENR |= 0x11; /* AND NOT 0x14 */2010-10-09 11:43 PM
hi
thanks for your help. but i dont realy understand if i use it this way RCC->APB2ENR |=RCC_APB2RSTR_IOPCRST | RCC_APB2RSTR_AFIORST; then i dont realy know the inital value of RCC->APB2ENR. and in this way RCC->APB2ENR =RCC_APB2RSTR_IOPCRST | RCC_APB2RSTR_AFIORST; i determine the value without assuming the inital value. right?