-
CW32l083 RTC 偏差值 sos
rtc运行一晚上时间比实际实际快了十多分钟 ,程序运行逻辑,程序运行后5分钟进入休眠模式,10分钟后rtc唤醒并打印当前时间 请教出现这种情况的原因是什么 rtc 配置 void my_rtc_Init(void) { RTC_InitTypeDef RTC_InitStruct = {0}; RTC_InitStruct.DateStruct.Day = 0x20; //设置日期,DAY、MONTH、YEAR必须为BCD方式,星期为0~6,代表星期日,星期一至星期六 RTC_InitStruct.DateStruct.Month = RTC_Month_March; RTC_InitStruct.DateStruct.Week = RTC_Weekday_Wednesday; RTC_InitStruct.DateStruct.Year = 0x24; RTC_InitStruct.TimeStruct.Hour = 0x09; //设置时间,HOUR、MINIUTE、SECOND必须为BCD方式,用户须保证HOUR、AMPM、H24之间的关联正确性 RTC_InitStruct.TimeStruct.Minute = 0x09; RTC_InitStruct.TimeStruct.Second = 0x00; RTC_InitStruct.TimeStruct.AMPM = 0; RTC_InitStruct.TimeStruct.H24 = 1; RTC_InitStruct.RTC_ClockSource = RTC_RTCCLK_FROM_LSI; RTC_Init(&RTC_InitStruct); // 用户需选定需要使用的时钟源 } /* 设置时钟 */ unsigned char at_cmd_setrtc(Timestamp tm){ RTC_DateTypeDef RTC_DateStruct = {0}; RTC_TimeTypeDef RTC_TimeStruct = {0}; RTC_DateStruct.Year = HexToBcd((unsigned char) tm.year); RTC_DateStruct.Month = HexToBcd((unsigned char) tm.month); RTC_DateStruct.Day = HexToBcd((unsigned char) tm.day); RTC_DateStruct.Week = HexToBcd((unsigned char) tm.week); RTC_TimeStruct.Hour = HexToBcd((unsigned char) tm.hour); RTC_TimeStruct.Minute = HexToBcd((unsigned char) tm.minute); RTC_TimeStruct.Second = HexToBcd((unsigned char) tm.second); RTC_TimeStruct.AMPM = 0; RTC_TimeStruct.H24 = 1; RTC_SetTime(&RTC_TimeStruct); RTC_SetDate(&RTC_DateStruct); return 0; } uint8_t *WeekdayStr[7]= {"SUN","MON","TUE","WED","THU","FRI","SAT"}; void showrtctime(void) { char out[20]; RTC_TimeTypeDef RTC_TimeStruct = {0}; RTC_DateTypeDef RTC_DateStruct = {0}; RTC_GetDate(&RTC_DateStruct); RTC_GetTime(&RTC_TimeStruct); sprintf(out,"20%02d-%02d-%02d %s",BcdToHex(RTC_DateStruct.Year),BcdToHex(RTC_DateStruct.Month),BcdToHex(RTC_DateStruct.Day),WeekdayStr[RTC_DateStruct.Week]); printf("current time: %s ",out); sprintf(out,"%02d:%02d:%02d",BcdToHex(RTC_TimeStruct.Hour),BcdToHex(RTC_TimeStruct.Minute),BcdToHex(RTC_TimeStruct.Second)); printf(" %s \r\n",out); } void set_rtcAwk(uint16_t interval) { RTC_AWTTypeDef RTC_AWTStruct = {0}; RTC_AWTCmd(DISABLE); NVIC_DisableIRQ(RTC_IRQn); interval = (uint16_t)(interval*0.125) - 1; printf("set_rtcAwk %d \r\n", interval); showrtctime(); RTC_AWTStruct.AWT_ARRValue = interval; //(interval+1)/0.125 RTC_AWTStruct.AWT_ClockSource = RTC_AWTSOURCE_FROM_RTC1HZ_8; //0.125hz RTC_AWTConfig(&RTC_AWTStruct); RTC_ClearITPendingBit(RTC_IT_AWTIMER); RTC_AWTCmd(ENABLE); RTC_ITConfig(RTC_IT_AWTIMER, ENABLE); NVIC_EnableIRQ(RTC_IRQn); } void RTC_IRQHandlerCallBack(void) { if (RTC_GetITState(RTC_IT_AWTIMER )) { showrtctime(); RTC_ClearITPendingBit(RTC_IT_AWTIMER); } } /****************************************************************************** * Local function prototypes ('static') ******************************************************************************/ void System_Clk_Config(void) { uint8_t res; RCC_HSI_Enable( RCC_HSIOSC_DIV2 ); //配置系统时钟为HSI 24M RCC_LSI_Enable(); RCC_AHBPeriphClk_Enable(RCC_AHB_PERIPH_FLASH, ENABLE); //打开FLASH时钟 FLASH_SetLatency(FLASH_Latency_1); //频率小等于24M需要配置FlashWait=1 REGBITS_SET(CW_FLASH->CR1, FLASH_CR1_STANDBY_Msk); //打开FLASH低功耗使能控制 res = RCC_SysClk_Switch( RCC_SYSCLKSRC_HSI ); //切换系统时钟到HSI if( res == 0x0U ) //切换系统时钟成功 { RCC_SystemCoreClockUpdate(24000000); RCC_HCLKPRS_Config(RCC_HCLK_DIV1); //HCLK(不分频)=PCLK RCC_PCLKPRS_Config(RCC_PCLK_DIV1); } else { while(1) { } } } void RCC_CLK_Config(void) { //外设时钟使能 __RCC_GPIOA_CLK_ENABLE(); __RCC_GPIOB_CLK_ENABLE(); __RCC_GPIOC_CLK_ENABLE(); __RCC_GPIOF_CLK_ENABLE(); __RCC_UART1_CLK_ENABLE(); __RCC_UART2_CLK_ENABLE(); __RCC_UART3_CLK_ENABLE(); __RCC_UART4_CLK_ENABLE(); __RCC_UART5_CLK_ENABLE(); __RCC_UART6_CLK_ENABLE(); //__RCC_SPI1_CLK_ENABLE(); __RCC_RTC_CLK_ENABLE(); __RCC_BTIM_CLK_ENABLE(); __RCC_DMA_CLK_ENABLE(); } /****************************************************************************** * Local variable definitions ('static') * ******************************************************************************/ /****************************************************************************** * Local pre-processor symbols/macros ('#define') ******************************************************************************/ /***************************************************************************** * Function implementation - global ('extern') and local ('static') ******************************************************************************/ /** ****************************************************************************** ** \brief Main function of project ** ** \return uint32_t return value, if needed ** ** This sample HSI switch to PLL, PLL switch to HSI. ** ******************************************************************************/ int32_t main(void) { System_Clk_Config(); RCC_CLK_Config(); //InitTick(24000000); my_rtc_Init(); set_rtcAwk(600); Sleep_Mode_Config(DEEP_SLEEP_MODE); //DEEP_SLEEP_MODE printf("test...\r\n"); while (1) { /* code */ if(1==devParam_t.enter_sleep) { showrtctime(); printf("enter_low_power_consumption_mode...\r\n"); Enter_Deep_Sleep_Mode(); devParam_t.enter_sleep=0; printf("exit_low_power_consumption_mode...\r\n"); showrtctime(); } } }
1635浏览量 0回复量 关注量 -
MM32SPIN系列使用dma spi clk始终8位之间有一个时间间隔 sos
我使用MM32SPIN27PF 使用dma与硬件spi进行开发 初始化代码如下: RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //SPI2 clk enable RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); //SPI_NSS GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_0); //SPI_SCK GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_0); //SPI_MISO GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_0); //SPI_MOSI GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_0); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_DataWidth = SPI_DataWidth_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; SPI_InitStructure.SPI_BaudRatePrescaler = spi_baud_div; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; SPI_Init(SPIx, &SPI_InitStructure); SPI_Cmd(SPIx, ENABLE); SPIM_TXEn(SPIx); SPIM_RXEn(SPIx); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //ʹÄÜDMA´«Êä //spi1 rx channel 2 DMA_DeInit(DMA1_Channel2); //½«DMAµÄͨµÀ2¼Ä´æÆ÷ÖØÉèΪȱʡֵ DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (SPI1->RXREG); //DMAÍâÉèADC»ùµØÖ· DMA_InitStructure.DMA_MemoryBaseAddr = rx; //DMAÄÚ´æ»ùµØÖ· DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC ; //Êý¾Ý´«Êä·½Ïò£¬´ÓÄÚ´æ¶ÁÈ¡·¢Ë͵½ÍâÉè DMA_InitStructure.DMA_BufferSize = rxbuffSize; //DMAͨµÀµÄDMA»º´æµÄ´óС DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //ÍâÉèµØÖ·¼Ä´æÆ÷²»±ä DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //ÄÚ´æµØÖ·¼Ä´æÆ÷µÝÔö DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //Êý¾Ý¿í¶ÈΪ8λDMA_PeripheralDataSize_Byte DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; //Êý¾Ý¿í¶ÈΪ8λDMA_MemoryDataSize_Byte DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //¹¤×÷ÔÚÕý³£»º´æģʽ DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; //DMAͨµÀ xÓµÓÐÖÐÓÅÏȼ¶ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //DMAͨµÀxûÓÐÉèÖÃΪÄÚ´æµ½ÄÚ´æ´«Êä DMA_Init(DMA1_Channel2, &DMA_InitStructure); //¸ù¾ÝDMA_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯DMAµÄͨµÀUSART1_Tx_DMA_ChannelËù±êʶµÄ¼Ä´æÆ÷ //spi1 tx channel 3 DMA_DeInit(DMA1_Channel3); //spi1 tx channel 3 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (SPI1->TXREG); //UART2_DMA_TX????J??? DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)tx; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//?????memory?????? DMA_InitStructure.DMA_BufferSize = txbuffSize;//SPI1_DMA_TX??????? DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel3, &DMA_InitStructure);//SPI1 tX?DMA???3 SPI_DMACmd(SPI1,SPI_DMAReq_EN,ENABLE); 请问有人遇到过这种情况吗? 请问这是芯片设计导致的正常情况吗?
3069浏览量 0回复量 关注量 -
关于GD32F450VET6参数问题 sos
代码中 关于位置的参数关系,还有含义,有谁能知道呢? /* TLI layer1 configuration */ tli_layer_init_struct.layer_window_leftpos = 80 + HORIZONTAL_SYNCHRONOUS_PULSE + HORIZONTAL_BACK_PORCH; tli_layer_init_struct.layer_window_rightpos = (80 + 247 + HORIZONTAL_SYNCHRONOUS_PULSE + HORIZONTAL_BACK_PORCH - 1); tli_layer_init_struct.layer_window_toppos = 20 + VERTICAL_SYNCHRONOUS_PULSE + VERTICAL_BACK_PORCH; tli_layer_init_struct.layer_window_bottompos = 20 + 118 + VERTICAL_SYNCHRONOUS_PULSE + VERTICAL_BACK_PORCH - 1; tli_layer_init_struct.layer_ppf = LAYER_PPF_RGB565; tli_layer_init_struct.layer_sa = 0xff; tli_layer_init_struct.layer_acf1 = LAYER_ACF1_PASA; tli_layer_init_struct.layer_acf2 = LAYER_ACF2_PASA; tli_layer_init_struct.layer_default_alpha = 0x80; //显示范围以外的透明度 tli_layer_init_struct.layer_default_blue = 0; //显示范围以外的背景蓝色 tli_layer_init_struct.layer_default_green = 0; //显示范围以外的背景绿色 tli_layer_init_struct.layer_default_red = 0; //显示范围以外的背景红色 tli_layer_init_struct.layer_frame_bufaddr = (uint32_t)&blended_address_buffer; tli_layer_init_struct.layer_frame_line_length = ((247 * 2) + 3); tli_layer_init_struct.layer_frame_buf_stride_offset = (247 * 2); tli_layer_init_struct.layer_frame_total_line_number = 118; tli_layer_init(LAYER1, &tli_layer_init_struct);
2015浏览量 0回复量 关注量 -
结构体按位对齐后的赋值
[i=s] 本帖最后由 slf123123 于 2021-4-19 09:13 编辑 [/i] [p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="]typedef unsigned long DWORD;[/font][/backcolor][/color][/p][p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="]#pragma pack(push) #pragma pack(1) typedef struct si { DWORD a:4; DWORD b:7; DWORD c:3; DWORD d:1; [/font][/backcolor][/color][/p][p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="] DWORD e:3; DWORD f:14; }si; #pragma pack(pop) [/font][/backcolor][/color][/p] [p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="] 如上所示这个结构体对齐后是四个字节[/font][/backcolor][/color][/p][p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="]然后[/font][/backcolor][/color][/p][p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="]uint8 buff[4];[/font][/backcolor][/color][/p][p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="]怎么将buff赋值给整个结构体[/font][/backcolor][/color][/p][p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="]struct si su={buff[0],buff[1],buff[2],buff[3]};[/font][/backcolor][/color][/p][p=24, null, left][color=rgb(34, 34, 38)][backcolor=rgb(255, 255, 255)][font="]这样赋值不行吗[/font][/backcolor][/color][/p]
3623浏览量 14回复量 关注量