论坛元老
 
- 积分
- 4057
- 金钱
- 4057
- 注册时间
- 2019-4-2
- 在线时间
- 282 小时
|
发表于 2021-11-17 13:23:20
|
显示全部楼层
python
------------------------------------------
import sensor, image, time, math, pyb
from pyb import UART,LED
import json
import ustruct
RED_LED_PIN = 2
uart = UART(3,115200) #定义串口3变量
uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
#stm32_pa9 对 openmv_p5
#stm32_pa10 对 openmv_p4
while(True):
if(uart.any()):
d=uart.readline(); #读串口数据
c=d.decode('uft-8');
print(d)
if(c=="1\r\n"):
cx=0;cy=3;length=0;
FH = bytearray([0x2C,0x12,cx,cy,length,0x5B])
uart.write(FH)
print(FH)
pyb.LED(RED_LED_PIN).on()
time.sleep(20)
pyb.LED(RED_LED_PIN).off()
time.sleep(20)
--------------------------------------------------------------------
stm32
--------------------------------------------------------------------
void usartSendStr(USART_TypeDef* USARTx,char *str)
{
uint16_t i = 0;
do{
usartSendByte(USARTx,*(str+i));
i++;
}while(*(str+i) != '\0');
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
int main(void)
{
OLED_Init();
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
USART1_Init();
//OLED_ColorTurn(0); //0正常显示,1 反色显示
//OLED_DisplayTurn(0); //0正常显示 1 屏幕翻转显示
while(1)
{
usartSendStr(USART1,"1\r\n");
delay_ms(50);
}
}
|
|