完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
打了5块样板,同一个程序不断下载测试,有一个板子一直正常,其它板子时好时坏,什么原因呢?怎样查找错误?故障时候扫描不到usb port,设备管理器提示未知设备(设备请求描述符失败)
#include "CH58x_common.h" #include "main.h" #include "ads1110.h" #include "atk_lora_01.h" extern void InitUSBDevPara(void); extern void InitUSBDevice(void); extern void USB_IRQProcessHandler( void ); extern UINT8 SendUSBData(UINT8 *p_send_dat,UINT16 send_len); extern UINT8 Ep1DataOUTLen ; extern UINT8 Ep1DataOUTFlag ; extern UINT8 Ep1OUTDataBuf[MAX_PACKET_SIZE]; uint8_t lora_send_data_process(uint8_t* txbuf,int32_t dat); //#define LORA_MASTER_MODE //#define LORA_SLAVE_MODE volatile uint32_t lora_AUX_flage = FALSE; uint16_t aux_timeout=1000; uint8_t ads1110_delay = 10; int32_t adcValue=0; uint8_t adc_txBuf[20]; uint8_t lora_txCnt=0; uint16_t master_add = 0x1000; uint16_t slave_addr = 0x0001; uint8_t master_channel = 20; void DebugInit( void ) { GPIOB_SetBits(led1_pin); GPIOB_ModeCfg( led1_pin, GPIO_ModeOut_PP_5mA ); GPIOB_ModeCfg( vout_pin, GPIO_ModeOut_PP_20mA ); } int main() { SetSysClock( CLK_SOURCE_PLL_60MHz ); DebugInit(); //PA9 printf("startn"); InitUSBDevPara(); InitUSBDevice(); PFIC_EnableIRQ( USB_IRQn ); I2CInit(); ads1110_mode(SINGLE_MODE|PGA1|SPS15|DRDY); lora_GPIO_cfg(); TMR0_TimerInit( FREQ_SYS / 10 ); // 设置定时时间 100ms TMR0_ITCfg( ENABLE, TMR0_3_IT_CYC_END ); // 开启中断 PFIC_EnableIRQ( TMR0_IRQn ); vout_on(); lora_Sta = receiveSta; while(1) { // SYS_ResetExecute(); // DelayMs(10); // led1_toggle; switch (lora_Sta) { case receiveSta: loraRxCnt = 0; while(LORA_AUX_IN() == GPIO_High_Level) { lora_AUX_flage = 1; } #ifdef LORA_MASTER_MODE if(Ep1DataOUTFlag == 1){ Ep1DataOUTFlag = 0; lora_clear_rxbuf(); for (uint8_t i = 0; i < Ep1DataOUTLen; ++i) { loraRxBuf[i] = Ep1OUTDataBuf[i]; } lora_Sta = sendSta; }else if(lora_AUX_flage ==1){ lora_AUX_flage =0; SendUSBData(loraRxBuf,loraRxCnt);// strlen(loraRxBuf)); } #else if(Ep1DataOUTFlag == 1){ Ep1DataOUTFlag = 0; lora_clear_rxbuf(); for (uint8_t i = 0; i < Ep1DataOUTLen; ++i) { loraRxBuf[i] = Ep1OUTDataBuf[i]; } if((loraRxBuf[0] == 'A') && (loraRxBuf[1] == 'T')){ lora_Sta = configrueSta; } else { // getADS1110(&adcValue); lora_Sta = sendSta; } }else if(lora_AUX_flage ==1){ lora_AUX_flage =0; // getADS1110(&adcValue); if((loraRxBuf[0] == 'A') && (loraRxBuf[1] == 'T')){ lora_Sta = configrueSta; } else { lora_Sta = sendSta; } } #endif break; case sendSta: #ifdef LORA_MASTER_MODE SendUSBData(loraRxBuf, strlen(loraRxBuf)); strcpy(loraRxBuf,"AT+CWMODE=0rn"); if(lora_set_model(DISABLE,loraRxBuf)==FALSE){ strcpy(adc_txBuf, "ERROR"); } DelayMs(50); lora_sendData(adc_txBuf, strlen(adc_txBuf)); SendUSBData(adc_txBuf, strlen(adc_txBuf)); lora_clear_rxbuf(); lora_Sta = receiveSta; #else //SendUSBData(loraRxBuf, loraRxCnt); strcpy(loraRxBuf,"AT+CWMODE=0rn"); if(lora_set_model(DISABLE,loraRxBuf)==FALSE){ strcpy(adc_txBuf, "ERROR"); } adc_txBuf[0] = master_add>>8; adc_txBuf[1] = master_add & 0x00ff; adc_txBuf[2] = master_channel; adc_txBuf[3] = adcValue>>24; adc_txBuf[4] = adcValue>>16; adc_txBuf[5] = adcValue>>8; adc_txBuf[6] = adcValue; DelayMs(50); lora_sendData(adc_txBuf, 7); SendUSBData(adc_txBuf, 7); lora_clear_rxbuf(); lora_Sta = receiveSta; #endif break; case configrueSta: lora_set_model(ENABLE,loraRxBuf); DelayMs(50); lora_sendCMD(loraRxBuf); aux_timeout = 1000; while(LORA_AUX_IN() == GPIO_Low_Level){ DelayMs(1); if(aux_timeout-- == 0){ break; } } aux_timeout = 1000; while(LORA_AUX_IN() == GPIO_High_Level){ DelayMs(1); if(aux_timeout-- == 0){ break; } } SendUSBData(loraRxBuf, strlen(loraRxBuf)); lora_clear_rxbuf(); lora_Sta = receiveSta; break; default:lora_Sta = receiveSta; break; } USB_IRQProcessHandler(); // if(ads1110_delay == 0){ // ads1110_delay=5; // getADS1110(&adcValue); // sprintf(txBuf,"%drn",adcValue); // SendUSBData(txBuf,strlen(txBuf)); // GPIOB_InverseBits(led1_pin); // } // 注意当主频为80M时,Sleep睡眠唤醒中断不可调用flash内代码。 // LowPower_Sleep( RB_PWR_RAM30K | RB_PWR_RAM2K ); //只保留30+2K SRAM 供电 // HSECFG_Current( HSE_RCur_100 ); // 降为额定电流(低功耗函数中提升了HSE偏置电流) } } unsigned int crc16(unsigned char *puchMsg, unsigned int usDataLen) { unsigned char i; unsigned int crc = 0xffff; unsigned char TT; while (usDataLen--) // ??????? { crc = crc ^ (*puchMsg); puchMsg++; for (i = 0; i < 8; i++) { TT = crc & 1; crc = crc >> 1; crc = crc & 0x7fff; if (TT == 1) crc = crc ^ 0xa001; crc = crc & 0xffff; } } return crc; } uint8_t lora_send_data_process(uint8_t* txbuf,int32_t dat){ uint8_t result = FALSE; uint8_t num = 0; uint16_t crc =0; txbuf[num++] = master_add >> 8; txbuf[num++] = master_add; txbuf[num++] = master_channel; txbuf[num++] = slave_addr >> 8; txbuf[num++] = slave_addr & 0x00ff; txbuf[num++] = 4; txbuf[num++] = dat >> 24; txbuf[num++] = dat >> 16; txbuf[num++] = dat >> 8; txbuf[num++] = dat ; crc = crc16(txbuf, num); txbuf[num++] = crc >> 8; txbuf[num++] = crc & 0x00ff; lora_sendData(loraTxBuf, num); return result; } uint8_t receive_data_decode(uint8_t *buf,uint8_t len){ uint8_t result = FALSE; uint16_t crc =0; crc = crc16(buf, len - 2); if(((crc & 0x00ff) == buf[len -2]) && ((crc >> 8) == buf[len -1])){ result = TRUE; } else { result = FALSE; } return result; } __INTERRUPT __HIGH_CODE void TMR0_IRQHandler( void ) // TMR0 定时中断 { if ( TMR0_GetITFlag( TMR0_3_IT_CYC_END ) ) { TMR0_ClearITFlag( TMR0_3_IT_CYC_END ); // 清除中断标志 led1_toggle; } } |
|
相关推荐
1个回答
|
|
无法识别的设备有可能跟硬件有关系,比如芯片焊接不好,外围电容有问题,供电不好。
如果都可以通过芯片内置的BOOT,借助USB接口进行下载,那基本可用排除硬件问题(因为USB下载时,至少说明焊接,供电和USB走线问题不大),如果USB下载都不行,那就不用查软件,先按照焊接,供电,芯片外围,USB走线查一下硬件问题。 上面的代码在进行USB设备枚举时,建议使用USB中断,这样才能及时响应主机的命令,因为前面的通讯还有比较大的延时,可能造成枚举失败,这部分可以参考EVT里面的USB从机例子进行移植。 |
|
|
|
只有小组成员才能发言,加入小组>>
453 浏览 1 评论
CH579M+RT-Thread,RTC从Sleep模式唤醒失败是什么原因?
2865 浏览 2 评论
2351 浏览 1 评论
801浏览 2评论
CH569通过HSPI实现USB3.0和FPGA高速双向通讯
626浏览 1评论
489浏览 1评论
CH32F103C8T6使用当前官网上的CDC例程会出现设备描述符请求失败
353浏览 1评论
628浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 09:41 , Processed in 0.998301 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号