2017-06-26 04:54 AM
2017-06-26 05:55 AM
Found a small error in code (and modified the starting post, see //here it is! ) and everything seems to be working. That error was not related to the issue, but it works now...
I'll ask here if something changes, Okay?
2017-07-04 07:56 AM
Seems like I should Initialize GPIO before setting up any UART clocks:
void init_uart7(){
__HAL_RCC_GPIOF_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
/**UART7 GPIO Configuration
PF7 ------> UART7_R
X PF6 ------> UART7_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; /*GPIO_MODE_AF_PP;*/
GPIO_InitStruct.Pull = GPIO_PULLUP;
//GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART7;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_UART7;
PeriphClkInitStruct.Uart7ClockSelection = RCC_UART7CLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{}
__HAL_RCC_UART7_CLK_ENABLE();
//now comes the initialization of USART6 params
//baud rate. calculated as in p1002 MCU_ReferenceManual
//UART7->BRR = 0xAFC4;//9600, over8 = 1; 8 bit data; no parity; 1 stop bit
UART7->BRR = 0x0EA3; //115200, over8=1; 8 bit data; no parity 1 stop bit
//USARTDIV=2*216000000/115200 = 3750d = 0x0EA6; 0x6 >> 1 = 3h ; BRR=0x0EA3
//UART7->CR3 |= USART_CR3_OVRDIS; //This bit is used to disable the receive overrun. Might be worth setting when receiving is invloved
//do not set this, data are going to get lost!
UART7->CR1 = 0x00;
UART7->CR2 = 0x00;
UART7->CR1 |= USART_CR1_RXNEIE; //enable interrupt on ORE=1 (overrun) or RXNE=1 (rx signal) in the USART_ISR. They should be cleaned after I suppose
NVIC_EnableIRQ(UART7_IRQn);
//USART6->CR1 &= ~USART_CR1_M; //word length: 8 bit
//USART6->CR2 &= ~USART_CR2_STOP; //1 stop bit
//p1029
//0b00000000000000000000000000000000
//M1(bit28)M0(bit12) -> 0;0 (1 Start bit, 8 data bits, n stop bits) Keep default, no change
UART7->CR1 |= USART_CR1_OVER8; //oversampling=8. involved in calculation of baud rate.
UART7->CR1 |= USART_CR1_RE; //enable receiver
UART7->CR1 |= USART_CR1_TE; //enable transmitter
UART7->CR1 |= USART_CR1_UE; //enable UART7
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Transmission works, reception does not work.
Defining interruptions is required to getthings better. One should define also this codein stm32f7xx_it.c :
void UART7_IRQHandler(void) {
//p1045 clear registers!
UART7->ICR |= USART_ICR_ORECF;
UART7->RQR |= USART_RQR_RXFRQ;
}�?�?�?�?�?�?
2017-07-05 02:09 AM
Interrupt handler is being called twice more than the actual number of recieved bytes. Here's edit to make it called exact times:
void UART7_IRQHandler(void) {
if ((UART7->ISR & USART_ISR_RXNE )!=0) {
//read the data, check it
uint8_t UART_data = UART7->RDR;
globalCounter++;
}
//p1045 clear registers!
UART7->ICR |= USART_ICR_ORECF;
UART7->RQR |= USART_RQR_RXFRQ;
}�?�?�?�?�?�?�?�?�?�?�?�?
2017-07-05 08:45 AM
Do not enable and process interrupts on transmission, like
UART7->CR1 |= USART_CR1_TXEIE
or
UART7->CR1 |= USART_CR1_
TCEIE
It is useless (and leads to bad things)