[debugging window][1]I have tried to print a message using USART1, the code is compiling but nothing is printed on the serial monitor, i have tried the same configuration ( except baud rate and clk enabling) on usart2 and everything works, this is my code, please anyone has faced the same probleme with keil, ? on mbed , both usart1 and usart2 are working fine, this is my new code version 2[debugging window][2] :
this is my code after some modification i have added a screen to show the debugging window, i have deleted ORR, and cleared ODR register for PIN9,
void USART1_Init(void);
void USART_write(int ch);
void DelayTimerUs1(int n);
//void DelayMS (int delay);
int main (void){
USART1_Init();
while(1){
USART_write('B');
USART_write('R');
USART_write('A');
USART_write('H');
//DelayMS (1);
DelayTimerUs1(10000);
}
}
void USART1_Init(void){
// Clear
USART1->CR1 &=~USART_CR1_UE;
USART1->CR1 &=~USART_CR1_M;
USART1->CR2 &=~USART_CR2_STOP;
USART1->CR1 &=~USART_CR1_PCE;
USART1->BRR = 0x1D4C;
USART1->CR1 = (USART_CR1_TE | USART_CR1_RE);
USART1->CR1 = USART_CR1_UE;
RCC->APB2ENR = RCC_APB2ENR_IOPAEN; /
GPIOA->ODR &=~ GPIO_ODR_ODR9;
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
GPIOA->CRH =( GPIO_CRH_MODE9_1 | GPIO_CRH_CNF9_1);
GPIOA->CRH &=~ GPIO_CRH_MODE9_0 | GPIO_CRH_CNF9_0;
RCC->APB2ENR = RCC_APB2ENR_USART1EN;
}
void USART_write( int ch){
while(!(USART1->SR & USART_SR_TXE)){} // we check if the transmit buffer is empty before sending the data
USART1->DR |= (ch & 0xFF );
}
void DelayTimerUs1(int n){
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->PSC = 7200;
TIM2->ARR = n;
TIM2->CNT = 0;
TIM2->CR1 = TIM_CR1_CEN;
for( int i =0; i<n; i++){
while (!(TIM2->SR & (1<<0))) {}
}
TIM2->SR &=~ (1<<0);
TIM2->CR1 &=~ TIM_CR1_CEN;
}
#include "stm32f10x.h" // Device header
void USART1_Init(void);
void USART_write(int ch);
void DelayTimerUs1(int n);
//void DelayMS (int delay);
int main (void){
USART1_Init();
while(1){
USART_write('B');
USART_write('R');
USART_write('A');
USART_write('H');
DelayTimerUs1(10000);
}
}
void USART1_Init(void){
USART1->CR1 &=~USART_CR1_UE;
USART1->CR1 &=~USART_CR1_M;
USART1->CR2 &=~USART_CR2_STOP;
USART1->CR1 &=~USART_CR1_PCE;
USART1->BRR |= 0x1D4C;
USART1->CR1 |= (USART_CR1_TE | USART_CR1_RE);
USART1->CR1 |= USART_CR1_UE;
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // enable clock for USART2TX which is connected to PA2 P180 Ref manual
GPIOA->ODR &=~ GPIO_ODR_ODR9;
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
GPIOA->CRH |= GPIO_CRH_MODE9_1 | GPIO_CRH_CNF9_1;
GPIOA->CRH &=~ GPIO_CRH_MODE9_0 | GPIO_CRH_CNF9_0;
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
//USART1->BRR |= 0x1D4C;
// 72Mhz -->USART2
//0x1D4C; // 9600--->USART1
//0x138A
//0xEA6
}
void USART_write( int ch){
while(!(USART1->SR & USART_SR_TXE)){} // we check if the transmit buffer is empty before sending the data
USART1->DR |= (ch & 0xFF ); // contains the received or transmitted data
//we put the data which we will send in DR register of the microcontroller
}
void DelayTimerUs1(int n){
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->PSC = 7200;
TIM2->ARR = n;
TIM2->CNT = 0;
TIM2->CR1 = TIM_CR1_CEN;
for( int i =0; i<n; i++){
while (!(TIM2->SR & (1<<0))) {}
}
TIM2->SR &=~ (1<<0);
TIM2->CR1 &=~ TIM_CR1_CEN;
}
```
[As you can see in the screen the debug window, i don't know exactly what happens][2]
}```
[1]: https://i.stack.imgur.com/n1QGx.png
[2]: https://i.stack.imgur.com/wbxnC.png