21ic问答首页 - AT32f423电池供电数据寄存器ERTC_BPRx半字操作不成功
AT32f423电池供电数据寄存器ERTC_BPRx半字操作不成功
gaolf_20002023-11-02
本帖最后由 gaolf_2000 于 2023-11-2 11:29 编辑
参照库里面的
void ertc_bpr_data_write(ertc_dt_type dt, uint32_t data)
{
__IO uint32_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 4);
*(__IO uint32_t *)reg = data;
}
uint32_t ertc_bpr_data_read(ertc_dt_type dt)
{
__IO uint32_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 4);
return (*(__IO uint32_t *)reg);
}
写的:
void ertc_bpr_16bitdata_write(uint16_t dt, uint16_t data)
{
__IO uint16_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 2);
*(__IO uint16_t *)reg = data;
}
uint16_t ertc_bpr_16bitdata_read(uint16_t dt)
{
__IO uint16_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 2);
return (*(__IO uint16_t *)reg);
}
时钟使能了,访问也使能了,但还是写不进去,读出来都是0xffff,不明白原因
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
pwc_battery_powered_domain_access(TRUE);
参照库里面的
void ertc_bpr_data_write(ertc_dt_type dt, uint32_t data)
{
__IO uint32_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 4);
*(__IO uint32_t *)reg = data;
}
uint32_t ertc_bpr_data_read(ertc_dt_type dt)
{
__IO uint32_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 4);
return (*(__IO uint32_t *)reg);
}
写的:
void ertc_bpr_16bitdata_write(uint16_t dt, uint16_t data)
{
__IO uint16_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 2);
*(__IO uint16_t *)reg = data;
}
uint16_t ertc_bpr_16bitdata_read(uint16_t dt)
{
__IO uint16_t reg = 0;
reg = ERTC_BASE + 0x50 + (dt * 2);
return (*(__IO uint16_t *)reg);
}
时钟使能了,访问也使能了,但还是写不进去,读出来都是0xffff,不明白原因
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
pwc_battery_powered_domain_access(TRUE);
赞0
比如写16位0x0001,实际上进行了32位写入,写入了0x00010001;
写8位0x0001,实际上进行了32位写入,写入了0x01010101;
评论
2023-11-12
赞0
评论
2023-11-12
赞0
{
__IO uint16_t *reg16 = (__IO uint16_t *)((uint32_t) ERTC +0x50+2*dt);
__IO uint32_t *reg32 = (__IO uint32_t *)((uint32_t) ERTC +0x50+4*dt);
CRM->apb1en_bit.pwcen =1;
PWC->ctrl_bit.bpwen=1; //PWC_CTRL 的BPWEN=1
ERTC->wp = 0XCA;//ERTC_WP 寄存器写入 0xCA,0x53
ERTC->wp = 0X53;
ERTC->ctrl_bit.bpr =1;
ERTC->dt1;
*reg16 = data;
reg16++;
*reg16 = data;
*reg32 = data+1;
ERTC->wp = 0Xff;
}
///16 bit 操作没问题。
操作前需要要解锁。
以上代码调试通过。
评论
2023-11-12
赞0
评论
2023-11-06
赞0
评论
2023-11-03
赞0
评论
2023-11-02
赞0
{
__IO uint16_t *reg = ERTC_BASE + 0x50 + (dt * 2);
*reg = data;
}
评论
2023-11-02
赞0
1698906248880.png (91.25 KB )
下载附件
2023-11-2 14:25 上传
评论
2023-11-02
赞0
评论
2023-11-02
您需要登录后才可以回复 登录 | 注册