我想实现的功能是openmv进行图片处理后,可以得到色块像素个数,将像素个数转为字符串类型并发送给msp430f5529,msp430f5529串口接收来自openmv发送的字符串数据后又反发送回去给openmv,请问这是可以实现的吗?也是通过UCA0TXBUF = UCA0RXBUF来进行的吗?
//msp430f5529代码
#include <msp430.h>
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
void Uart_Init(void)
{
P3SEL |= BIT3+BIT4;
UCA0CTL1 |= UCSWRST;
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 6;
UCA0BR1 = 0;
UCA0MCTL = UCBRS_0 + UCBRF_13 + UCOS16;
UCA0CTL1 &= ~UCSWRST;
UCA0IE |= UCRXIE;
_EINT();
}
void send_char()
{
UCA0TXBUF = UCA0RXBUF;
while (!(UCA0IFG&UCTXIFG));
}
void send_string(unsigned char *p)
{
while(*p!='\0')
{
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF=*p;
*p++;
}
}
char rec;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
Uart_Init();
__bis_SR_register(GIE);
while(1)
{
send_char();
delay_ms(1000);
}
}
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,4))
{
case 2:
while (!(UCA0IFG&UCTXIFG));
rec = UCA0RXBUF;
break;
default: break;
}
}
//openmv代码
import sensor, image, time
from pyb import LED
from pyb import UART
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
uart = UART(3, 9600)
uart.init(9600, bits=8, parity=None, stop=1)
clock = time.clock()
yellow_threshold = (52, 2, 108, 21, 102, -7)
LED(1).on()
LED(2).on()
LED(3).on()
def receive_data():
global uart
if (uart.any()):
tmp_data = uart.read();
#tmp_data = uart.readline();
print(tmp_data)
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([yellow_threshold])
if blobs:
for blob in blobs:
img.draw_rectangle(blob.rect())
num = blob.pixels()
uart.write(str(num))
receive_data();
time.sleep_ms(1000)
else:
print("no")
|