|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- /**
- ******************************************************************************
- **˵003Ŀд
- **ܣд
- **ߣBruce
- **ڣ2017.6.8
- ******************************************************************************
- **/
-
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "printf.h"
- #include "USART2.h"
- #include "LED.h"
- #include "delay.h"
- #include "nrf24L01.h"
- #include "DataProc.h"
- #include "tim.h"
- #include "flash.h"
- #include "LCD.h"
-
-
-
- /* Functions ---------------------------------------------------------*/
- void RCC_Configuration(void);
- void NVIC_Configuration(void);
-
- void IWDG_Init(u8 prer,u16 rlr);
- void IWDG_Feed(void);
-
- extern unsigned char txBuf[32];
- extern u8 protocol_config_flg;
- extern u8 first_clear_flag;
-
- #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
-
- #define SYSCLK_FREQ_24MHz 24000000
- #else
- #define SYSCLK_FREQ_72MHz 72000000
- #endif
-
- /** @addtogroup STM32F10x_StdPeriph_Template
- * @{
- */
-
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- #if 1
- #define SCAN_ADDRESS (unsigned char*)"\x34\x43\x10\x10\x01"
- #define SCAN_SETUPVALUE 0x07
- #define SCAN_TX_ADR_WIDTH (5) //3???????
- #define SCAN_RX_ADR_WIDTH (5) //3???????
- #define SCAN_RX_PLOAD_WIDTH (10) //32?????????
- #define SCAN_TX_PLOAD_WIDTH (10) //32?????????
- #define SCAN_RF_CRC (0x00)
- #define SCAN_RF_ENAA (0x01)
- #define SCAN_TX_CHNL (40) //??????1
- #define SCAN_RX_CHNL (40) //??????2
- #define SCAN_DYNPD (0x01)
- #define SCAN_FEATURE (0x07)
-
- void NRF24L01_TELPO_RX_Mode(SPIType spiNum,unsigned char* addr,
- unsigned char addrlen,
- unsigned char rf_channel,
- unsigned char rf_setup,
- unsigned char rf_crc,
- unsigned char rf_enaa,
- unsigned char len,
- unsigned char dynpd,
- unsigned char feature)
- {
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,addrlen - 2);//???? --3??
- NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)addr,addrlen);//?RX????
- NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)addr,addrlen);//?TX????
-
-
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,rf_enaa); //????0?????
-
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//????0?????
-
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,rf_channel); //??RF????
-
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,rf_setup);//??TX????,0db??,1Mbps,???????
-
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,len);//????0???????
-
-
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, (0x3b | rf_crc));//???????????;PWR_UP,EN_CRC,16BIT_CRC,????
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,dynpd);
-
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,feature);
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //??TX_DS?MAX_RT????
- NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //??RX FIFO???
- }
-
-
- void NRF24L01_RX_TelPo_CONFIG1(SPIType spiNum)
- {
- if(spiNum == SPI_PORT1){
- SPI1_CE =0;
- }else{
- SPI2_CE=0;
- }
- NRF24L01_TELPO_RX_Mode(spiNum,SCAN_ADDRESS,SCAN_RX_ADR_WIDTH,SCAN_RX_CHNL,
- SCAN_SETUPVALUE,SCAN_RF_CRC,SCAN_RF_ENAA,
- SCAN_RX_PLOAD_WIDTH,SCAN_DYNPD,SCAN_FEATURE);
- if(spiNum == SPI_PORT1){ //CEΪ,ģʽ
- SPI1_CE =1;
- }else{
- SPI2_CE=1;
- }
- }
- #endif
- u8 NRF24L01_RxPacket1(SPIType spiNum,u8 *rxbuf,unsigned char rxLen)
- {
- u8 sta;
- SPI_SetSpeed(spiNum,SPI_BaudRatePrescaler_16);
- //SPI_SetSpeed(spiNum,SPI_BaudRatePrescaler_8); //spi???9Mhz(24L01???SPI???10Mhz)
- sta=NRF24L01_Read_Reg(spiNum,STATUS); //?????????
-
- if(sta&RX_OK)//?????
- {
-
-
- NRF24L01_Read_Buf(spiNum,RD_RX_PLOAD,rxbuf,rxLen); //????
- NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //??RX FIFO???
- NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,sta); //??TX_DS?MAX_RT????
- delay_5us(20);
- return 0;
- }
- return 1;//???????
- }
-
-
- int main(void)
- {
- /*!< At this stage the microcontroller clock setting is already configured,
- this is done through SystemInit() function which is called from startup
- file (startup_stm32f10x_xx.s) before to branch to application main.
- To reconfigure the default setting of SystemInit() function, refer to
- system_stm32f10x.c file
- */
- //SCB->VTOR = FLASH_BASE | 0x10000; /* Vector Table Relocation in Internal FLASH. */
-
- RCC_Configuration(); //ϵͳʱ
-
- NVIC_Configuration(); //ж
-
- IWDG_Init(4,625); //(4*2^4)*625/40 ms = 1s Źʱ1s
- IWDG_Feed();
-
- TIM3_Int_Init(9,7199);
-
- led_init(); //LED IO
- #if LCD
- lcd_init(); //LCD
- AttenuatorConfig(); //˥
- #endif
-
- USART_Configuration(); //13ʼ 1Ϊ115200 3Ϊ4800
-
- USART2_Init(115200); //2ʼ Ϊ115200 Debug
-
- NRF24L01_Init(); //24L01 IO
-
- IWDG_Feed();
- // while(NRF24L01_Check(SPI_REV)){ //NRF24L01 1Ƿ
- // printf("The 2.4G Error!");
- // }
- #if 1
- while(NRF24L01_Check(SPI_SEND)){ //NRF24L01 2Ƿ
- printf("The 2.4G Error!");
- }
- #endif
- Data_Init(); //ݳʼ
-
- IWDG_Feed();
- led0=~led0;
- delay_ms(200);
- led0=~led0;
-
- DegugPrintf("123456",6);
- SendUSART2Str("\n");
-
- IWDG_Feed();
- #if 0
- while(1)
- {
- NRF24L01_RX_TelPo_CONFIG1(SPI_SEND);
- while(1)
- {
- u8 Rx_Buffer[32] = {0};
-
- if (!NRF24L01_RxPacket1(SPI_SEND,Rx_Buffer,sizeof(Rx_Buffer)))
- {
- break;
- }
-
- IWDG_Feed();
- }
- IWDG_Feed();
- }
- #endif
- printf("\nPCͨð汾V2.4-20190906\n");
- // SendUartData("123456",6,USART2);
- // printf("System Clock = %d\r\n",SystemCoreClock);
-
- NRF24L01_RX_Mode(SPI_SEND);
- // NRF24L01_RX_Mode_NOACK(SPI_SEND);
- //while(1)
- //{
- // RF24_CarrierTest(SPI_SEND,32);
- // delay_ms(100);
- // IWDG_Feed();
- //}
-
- #if 1
- Readpara_from_flash(); //ݲӡ
- protocol_config_flg = Save_Buffer[2*0];
- switch(protocol_config_flg)
- {
- case 0:
- {
- printf("Э\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"JIANGXI",7);
- #endif
- break;
- }
- case 1:
- {
- printf("첨Э\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"TELPO",5);
- #endif
- break;
- }
- case 2:
- {
- printf("Э\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"YUNNAN",6);
- #endif
- break;
- }
- case 3:
- {
- printf("Э\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"GUIZHOU",7);
- #endif
- break;
- }
- case 4:
- {
- printf("ĴЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"SICHUAN",7);
- #endif
- break;
- }
- case 5:
- {
- printf("ɹЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"NEIMENGGU",9);
- #endif
- break;
- }
- case 6:
- {
- printf("Э\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"ANHUI",5);
- #endif
- break;
- }
- case 7:
- {
- printf("ɽŵЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"SHANXI",6);
- #endif
- break;
- }
- case 8:
- {
- printf("VCOM\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"VCOM",4);
- #endif
- break;
- }
- case 9:
- {
- printf("\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"LIAONING.DIAN",13);
- #endif
- break;
- }
- case 10:
- {
- printf("ƶ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"LIAONING.YI",11);
- #endif
- break;
- }
- case 11:
- {
- printf("TpרЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"TP",2);
- #endif
- break;
- }
- case 12:
- {
- printf("ɹƶЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"NEIMENGGU.YI",12);
- #endif
- break;
- }
- case 13:
- {
- printf("ƶЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"GUANGXI.YI",10);
- #endif
- break;
- }
- case 14:
- {
- printf("ĴЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"SICHUN.DIAN",11);
- #endif
- break;
- }
- case 15:
- {
- printf("Э\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"FUJIANZHENZHUO",14);
- #endif
- break;
- }
- case 16:
- {
- printf("ľЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"SUZHOUMULANG",10);
- #endif
- break;
- }
- case 17:
- {
- printf("ƶЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"CHONGQIN.YI",11);
- #endif
- break;
- }
- case 18:
- {
- printf("ɽƶЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"SHANXI.YI",9);
- #endif
- break;
- }
- case 19:
- {
- printf("ƶЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"GANSU.YI",9);
- #endif
- break;
- }
- case 20:
- {
- printf("ŴЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"XDF",3);
- #endif
- break;
- }
- case 21:
- {
- printf("ºЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"DH",2);
- #endif
- break;
- }
- case 22:
- {
- printf("յЭ\r\n");
- #if LCD
- vDispClearLine(1);
- vDispStr(1,1,"AHDX",4);
- #endif
- break;
- }
- }
- #endif
-
- #if 0
- NRF24L01_RX_TelPo_CONFIG1(SPI_SEND);
- while(1)
- {
-
- u8 Rx_Buffer[32] = {0};
- if (!NRF24L01_RxPacket(SPI_SEND,Rx_Buffer))
- {
- break;
- }
-
- }
-
- #endif
-
-
-
-
- /* Infinite loop */
- //SendConsoleByte(protocol_config_flg); //ԣظPC
- //NRF24L01_RX_Mode_NOACK_VCOM(SPI_SEND);
- first_clear_flag = 1;
- delay_ms(50);
- while (1)
- {
-
- // while(1) //
- // {
- // if(DataProc_A4_nrf())
- // break;
- // }
- DataProc_1356(); //13.56Mݴ
- #if LCD
- DataProc_RecNrf24L01();
- #endif
-
- DataProc_USART1(); //1ݴPCͨ
-
- // DataProc_Nrf24l01_SPI2();
- }
- }
-
-
-
- void RCC_Configuration(void)
- {
- #if 0
- ErrorStatus HSEStartUpStatus; //öٱʱӵ״̬
- RCC_DeInit(); //RCCϵͳãDebug
- RCC_HSEConfig(RCC_HSE_ON); //ʹܸʱԴHSE
- HSEStartUpStatus = RCC_WaitForHSEStartUp(); //ȴHSEȶ
- if(HSEStartUpStatus == SUCCESS)
- {
- RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
- RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK
- RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2
-
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- RCC_PLLCmd(ENABLE);
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET){}
-
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
- while(RCC_GetSYSCLKSource() != 0x08){}
- }
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA |RCC_APB2Periph_AFIO |RCC_APB2Periph_GPIOB , ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
- #else
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
-
- /* Select AHB clock(HCLK) as SysTick clock source */
- SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
-
- /* SysTick interrupt each 10ms with HCLK equal to 72MHz */
- SysTick_Config(240000);
-
- #endif
- }
-
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
-
- NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //ô2ж
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //ռȼ1
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //ȼ2
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹж
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; //ô3ж
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //ռȼ1
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //ȼ1
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹж
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //ô1ж
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ռȼ0
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //ȼ1
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹж
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //öʱ3ȫж
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ռȼ0
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //ȼΪ0
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹ
- NVIC_Init(&NVIC_InitStructure);
-
- }
-
- /*
- *Źʼ
- *prer:Ƶ0-73λЧ
- *Ƶӣ4*2^prer256
- *rlr:װؼĴֵ11λЧ
- *Tout=((4*2^prer)*rlr)/40 (ms)
- */
- void IWDG_Init(u8 prer,u16 rlr)
- {
- IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); // ʹܶԼĴIWDG_PRIWDG_RLRIJ
- IWDG_SetPrescaler(prer); //IWDGԤƵֵ:prer
- IWDG_SetReload(rlr); //IWDGֵ
- IWDG_ReloadCounter(); //ֵIWDG
- IWDG_Enable(); //ʹIWDG
- }
-
- /**
- * ι
- */
- void IWDG_Feed(void)
- {
- IWDG_ReloadCounter(); /*reload*/
- }
-
- #ifdef USE_FULL_ASSERT
-
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
-
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
-
- /**
- * @}
- */
-
-
- /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|