cancel
Showing results for 
Search instead for 
Did you mean: 

Registers aren't changing when written

AHass.1
Associate II

Dear community,

I am programming an ST32F407VE for the first time (I don't use the Cube32IDE though). First, I made an on board LED blink, so I am pretty certain that my toolchain and framework work properly. In the next step, I wanted to implement a low-power IrDA interface.

However, if I try to write to the registers of USART6 (see code below), according to my debugging tool, these registers don't change at all. They simply keep their reset state. Other registers like the Rx and GPIO registers do change according to my code.

#include "irda.h"
#include "Arduino.h"
#include "stm32f4xx.h"
 
static char irda_initialized = 0;
 
void initIrDA(void)
{
	if (!irda_initialized)
	{
		USART6->GTPR |= (1<<USART_GTPR_PSC_Pos);
		USART6->CR1 |= (1<<USART_CR1_UE_Pos);
		/*
		USART6->CR1 |= (1<<USART_CR1_UE_Pos) 		// Enable USART
					  | (1<<USART_CR1_PEIE_Pos) 		// Enable Interrupts for parity errors
					 | (1<<USART_CR1_IDLEIE_Pos)	// Enable Interrupt when idle line is detected
					 | (1<<USART_CR1_TE_Pos)		// Enable Transmitter
					 | (1<<USART_CR1_RE_Pos);		// Enable Receiver
		/* nothing to be configured in CR2 register */
		// USART->CR2 = ;
		USART6->CR3 |= (1<<USART_CR3_IREN_Pos)		// IrDA mode enabled
					 | (1<<USART_CR3_IRLP_Pos);		// select IrDA low power mode
		irda_initialized = 1;
	}
}

Any help would be appreciated, I am really in desperation.

Sincerely,

1 ACCEPTED SOLUTION

Accepted Solutions
Ozone
Lead

Power to the respective peripheral unit must be enabled before explicitly (RCC).

Other devices react with a hardfault on such occasions.

View solution in original post

2 REPLIES 2
Ozone
Lead

Power to the respective peripheral unit must be enabled before explicitly (RCC).

Other devices react with a hardfault on such occasions.

Thank you very much. That was the problem. I did not turn on the periphery clock so the UART was turned off the whole time. I am not used to this concept since in the ATmega series the periphery registers usually have an enable bit. I think it could be made clearer in the documentation (in my case document RM0090) that you need to turn on the periphery in a whole set of extra registers, maybe a small hint in the chapter could be helpful.

For those who have the same or similar problems: for USART6, I needed to set the USART6EN bit in the RCC_APB2ENR register.

Thank you very much again.