2017-04-25 03:21 AM
I have the following structs (from a library I'm using) with some fields and I would like to assign with OR operation a new value. But I'm debugging and I can't see how anything is writing there:
typedef struct {
TIM_TypeDef *Instance; /*!< Register base address */
TIM_Base_InitTypeDef Init; /*!< TIM Time Base required parameters */
HAL_TIM_ActiveChannel Channel; /*!< Active channel */
DMA_HandleTypeDef *hdma[7]; /*!< DMA Handlers array This array is accessed by a @ref DMA_Handle_index */
HAL_LockTypeDef Lock; /*!< Locking object */
__IO HAL_TIM_StateTypeDef State; /*!< TIM operation state */
}TIM_HandleTypeDef;
typedef struct
{
__IO uint32_t CR1; /*!< TIM control register 1, Address offset: 0x00 */
__IO uint32_t CR2; /*!< TIM control register 2, Address offset: 0x04 */
__IO uint32_t SMCR; /*!< TIM slave mode control register, Address offset: 0x08 */
__IO uint32_t DIER; /*!< TIM DMA/interrupt enable register, Address offset: 0x0C */
__IO uint32_t SR; /*!< TIM status register, Address offset: 0x10 */
__IO uint32_t EGR; /*!< TIM event generation register, Address offset: 0x14 */
__IO uint32_t CCMR1; /*!< TIM capture/compare mode register 1, Address offset: 0x18 */
__IO uint32_t CCMR2; /*!< TIM capture/compare mode register 2, Address offset: 0x1C */
__IO uint32_t CCER; /*!< TIM capture/compare enable register, Address offset: 0x20 */
__IO uint32_t CNT; /*!< TIM counter register,
...
} TIM_TypeDef;
I have a part of code where I defined:
TIM_HandleTypeDef TIMER_Struct;
And I would like to access the field 'CR1' of TIM_TypeDef struct that is '*Instance' field of TIM_HandleTypeDef. So I have done it by this way in a function:
void DRV_TIMER_init(void)
{
...
TIMER_Struct.Instance = TIMx;//TIM7
TIMER_Struct.Init.Period = 100 - 1;
TIMER_Struct.Init.Prescaler = uwPrescalerValue;
TIMER_Struct.Init.ClockDivision = 0; // these accesses work
TIMER_Struct.Instance -> CR1 |= 0x01 << 3; // this no works
...
}
Even if I write directly:
TIMER_Struct.Instance -> CR1 = 0xFFFFFFFF;
It stills without having effect.
I think It could be a fact that I'm not controlling appropiately the pointer access or similar. But I don't see how can I access and modify the content of the commented field. Since I can see (debug mode) how the rest of struct fields updates are writen correctly.
Any correction suggested here?
TIMER_Struct.Instance -> CR1 = 0xFFFFFFFF;
I try different ways to get it with no success. I need new ideas. How would you do if you want write there?
Thanks in advance.
#pointers #hal-tim-structsSolved! Go to Solution.
2017-04-26 06:09 AM
no, there is no difference in the case of this register.
2017-04-26 06:34 AM
Thanks for the clarification, Max!!!
2017-04-27 03:27 AM
I think there is precedence involved:
your instruction could be TIMx->CR1 =(TIMx-> CR1 | 0x1) <<3;
or it could be TIMx->CR1 =TIMx-> CR1 | (0x1 <<3);
I believe you want the latter one and since 1<<3 is 8
try this TIMx->CR1 |=8; in your case
Instance
->
CR1
|=
8
;
if this works let me know
if not sorry for wasting your time
Yves
2017-04-27 08:13 AM
Hi David, Yes second one. I think you are all right and your idea is more exact than the first one. When you have a register with a concret value and you don't want modify the rest of bits except one, the best solution is your second one. The first one only will be correct if I have all 0x00. If not I will be shifting the rest of bits and I don't want this.
Am I wrong?