这是设置输入捕获的代码配置
TIM3_Cap_Init(0XFFFF,72-1);
void TIM3_Cap_Init(u16 arr,u16 psc)
{
RCC->APB1ENR|=1<<1; //tim3 ʱÖÓʹÄÜ
RCC->APB2ENR|=1<<2; //PORTAʱÖÓʹÄÜ
RCC->APB2ENR|=1<<3; //PORTBʱÖÓʹÄÜ
RCC->APB2ENR|=1<<0; //AFIOʱÖÓʹÄÜ
// AFIO->MAPR|=2<<8; //TIM2????
GPIOA->CRL&=0X00FFFFFF; //PA6,PA7
GPIOA->CRL|=0X88000000; //PA6,PA7
GPIOA->ODR&=0xFFFFFF3F; //PA6 PA7 ÏÂÀ
GPIOB->CRL&=0xFFFFFF00; //PB0,PB1
GPIOB->CRL|=0x00000088; //PB0,PB1
GPIOB->ODR&=0xFFFFFFFC; //PB0,PB1 ÏÂÀ
TIM3->ARR=arr;
TIM3->PSC=psc;
//CH1
TIM3->CCMR1|=1<<0; //CC1S=01 Ñ¡ÔñÊäÈë¶Ë IC1Ó³Éäµ½TI1ÉÏ
TIM3->CCMR1|=1<<4; //IC1F=0001 ÅäÖÃÊäÈëÂ˲¨Æ÷ ÒÔFck_int²ÉÑù£¬2¸öʼþºóÓÐЧ
TIM3->CCMR1|=0<<2; //IC1PS=00 ÅäÖÃÊäÈë·ÖƵ£¬²»·ÖƵ
TIM3->CCER|=0<<1; //CC1P=0 ÉÏÉýÑز¶»ñ
TIM3->CCER|=1<<0; //CC1E=1 ÔÊÐí²¶»ñ¼ÆÊýÆ÷µÄÖµµ½²¶»ñ¼Ä´æÆ÷ÖÐ
//CH2
TIM3->CCMR1|=1<<8; //CC2S=01 ͬÉÏ
TIM3->CCMR1|=1<<12; //IC2F=0001 ..
TIM3->CCMR1|=0<<10; //IC2PS=00 ..
TIM3->CCER|=0<<5; //CC2P=0 ..
TIM3->CCER|=1<<4; //CC2E=1 ..
//CH3
TIM3->CCMR2|=1<<0; //CC3S=01 ..
TIM3->CCMR2|=1<<4; //IC3F=0001 ..
TIM3->CCMR2|=0<<2; //IC3PS=00 ..
TIM3->CCER|=0<<9; //CC3P=0 ..
TIM3->CCER|=1<<8; //CC3E=1 ..
//CH4
TIM3->CCMR2|=1<<8; //CC4S=01 ..
TIM3->CCMR2|=1<<12; //IC4F=0001 ..
TIM3->CCMR2|=0<<10; //IC4PS=00 ..
TIM3->CCER|=0<<13; //CC4P=0 ..
TIM3->CCER|=1<<12; //CC4E=1 ..
//ÖжÏʹÄÜ
TIM3->DIER|=1<<1; //ÔÊÐí²¶»ñ1ÖжÏ
TIM3->DIER|=1<<2; //ÔÊÐí²¶»ñ2ÖжÏ
TIM3->DIER|=1<<3; //ÔÊÐí²¶»ñ3ÖжÏ
TIM3->DIER|=1<<4; //ÔÊÐí²¶»ñ4ÖжÏ
TIM3->DIER|=1<<0; //ÔÊÐí¸üÐÂÖжÏ
TIM3->CR1|=0x01; //ʹÄܶ¨Ê±Æ÷3
}
void main()
{
while(1)
{
if(TIM3CH1_CAPTURE_STA&0X80) //???????????
{
temp1=TIM3CH1_CAPTURE_STA&0X3F;
temp1*=65536; //??????
temp1+=TIM3CH1_CAPTURE_Date2;
temp1-=TIM3CH1_CAPTURE_Date1; //?????????
//if (temp1 != 65536)
printf("TIM3_CH1_HIGH:%d us\r\n",temp1); //?????????
TIM3CH1_CAPTURE_Date1=0;
TIM3CH1_CAPTURE_STA=0; //???????
}
if(TIM3CH2_CAPTURE_STA&0X80) //???????????
{
temp2=TIM3CH2_CAPTURE_STA&0X3F;
temp2*=65536; //??????
temp2+=TIM3CH2_CAPTURE_Date2;
temp2-=TIM3CH2_CAPTURE_Date1; //?????????
//if (temp2 != 65536)
printf("TIM3_CH2_HIGH:%d us\r\n",temp2); //?????????
TIM3CH2_CAPTURE_Date1=0;
TIM3CH2_CAPTURE_STA=0; //???????
}
if(TIM3CH3_CAPTURE_STA&0X80) //???????????
{
temp3=TIM3CH3_CAPTURE_STA&0X3F;
temp3*=65536; //??????
temp3+=TIM3CH3_CAPTURE_Date2;
temp3-=TIM3CH3_CAPTURE_Date1; //?????????
//if (temp3 != 65536)
printf("TIM3_CH3_HIGH:%d us\r\n",temp3); //?????????
TIM3CH3_CAPTURE_Date1=0;
TIM3CH3_CAPTURE_STA=0; //???????
}
if(TIM3CH4_CAPTURE_STA&0X80) //???????????
{
temp4=TIM3CH4_CAPTURE_STA&0X3F;
temp4*=65536; //??????
temp4+=TIM3CH4_CAPTURE_Date2;
temp4-=TIM3CH4_CAPTURE_Date1; //?????????
//if (temp4 != 65536)
printf("TIM3_CH4_HIGH:%d us\r\n",temp4); //?????????
TIM3CH4_CAPTURE_Date1=0;
TIM3CH4_CAPTURE_STA=0; //???????
}
}
}
这个是设置pwm输出的配置 TIM_SetCompare1(TIM3, 100); 可以正常输出pwm
Timer3_Init(19999,71);
void Timer3_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
/* GPIOB Configuration: TIM3 CH1 (PA6) and TIM3 CH2 (PA7) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* GPIOB Configuration: TIM3 CH3 (PB0) and TIM3 CH4 (PB1) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler =psc;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Disable);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Disable);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Disable);
TIM_Cmd(TIM3, ENABLE);
}
钱泰多 说:晕哥 说:W600 了解一下: https://whycan.cn/t_1928.html
据说功耗比 ESP8266 高些
我看了,主频太低了,1mbyte flash应该做不了故事机
存代码肯定够了, 音频资源文件存TF卡.
esp32上面的代码最后编译出来用了2.5m,解码库什么的太多了。这个芯片做故事机不太可能,而且跑语音那些算法要很高的主频呢
W600 了解一下: https://whycan.cn/t_1928.html
据说功耗比 ESP8266 高些
我看了,主频太低了,1mbyte flash应该做不了故事机
谢谢晕哥,这里有找到意外别的东西
已经解决问题,esp32原版的编译工具链里面其实已经自带了pyhon,是不用额外下载的,只需要配置好path就可以
msys32/etc/profile.d/esp32_toolchain
这里面改成
export PATH="/mingw32/bin:/usr/local/bin:/usr/bin:/bin:/c/windows/system32:/c/windows:/c/windows/system32/wbem:/opt/xtensa-esp32-elf/bin"
就能找到msys32/mingw32/bin里面的python了,是2.7的
自己在mingw32里更新的python是3.6的,打开串口可能有问题,估计原来的代码是用python2.7写的
命令行下编译则是这样,COM4我看了驱动管理器没有错
sky@DESKTOP-FEE8B4U MSYS /g/RD/Pro/ESP32/official/msys32/esp-adf/esp-idf/examples/get-started/hello_world
$ make flash
G:/RD/Pro/ESP32/official/msys32/esp-adf/esp-idf/make/project.mk:56: esp-idf build system only supports MSYS2 in "MINGW32" mode. Consult the ESP-IDF documentation for details.
/esp-adf/esp-idf/make/project.mk:56: esp-idf build system only supports MSYS2 in "MINGW32" mode. Consult the ESP-IDF documentation for details.
Flashing binaries to serial port /COM4 (app at offset 0x10000)...
esptool.py v2.1
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/serial/serialposix.py", line 288, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/COM4'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/esp-adf/esp-idf/components/esptool_py/esptool/esptool.py", line 2524, in <module>
_main()
File "/esp-adf/esp-idf/components/esptool_py/esptool/esptool.py", line 2517, in _main
main()
File "/esp-adf/esp-idf/components/esptool_py/esptool/esptool.py", line 2246, in main
esp = chip_class(args.port, initial_baud)
File "/esp-adf/esp-idf/components/esptool_py/esptool/esptool.py", line 177, in __init__
self._port = serial.serial_for_url(port)
File "/usr/lib/python3.6/site-packages/serial/__init__.py", line 90, in serial_for_url
instance.open()
File "/usr/lib/python3.6/site-packages/serial/serialposix.py", line 291, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /COM4: [Errno 2] No such file or directory: '/COM4'
make: *** [/esp-adf/esp-idf/components/esptool_py/Makefile.projbuild:55:flash] 错误 1
17:44:06 **** Build of configuration Default for project esp-adf ****
bash G:/RD/Pro/ESP32/official/msys32/esp-adf/esp-idf/tools/windows/eclipse_make.sh flash
eclipse_make.sh has been replaced with eclipse_make.py. Check the Windows Eclipse docs for the new command.
This shell script will continue to work until the next major release.
Traceback (most recent call last):
File "G:/RD/Pro/ESP32/official/msys32/esp-adf/esp-idf/tools/windows/eclipse_make.py", line 36, in <module>
main()
File "G:/RD/Pro/ESP32/official/msys32/esp-adf/esp-idf/tools/windows/eclipse_make.py", line 28, in main
print("Running make in '%s'" % check_path(os.getcwd()))
File "G:/RD/Pro/ESP32/official/msys32/esp-adf/esp-idf/tools/windows/eclipse_make.py", line 23, in check_path
winpath = winpath.replace("\\", "/") # make consistent with forward-slashes used elsewhere
TypeError: a bytes-like object is required, not 'str'
17:44:07 Build Finished. 0 errors, 0 warnings. (took 385ms)