|
我想實(shí)現(xiàn)的功能是openmv進(jìn)行圖片處理后,可以得到色塊像素個(gè)數(shù),將像素個(gè)數(shù)轉(zhuǎn)為字符串類(lèi)型并發(fā)送給msp430f5529,msp430f5529串口接收來(lái)自openmv發(fā)送的字符串?dāng)?shù)據(jù)后又反發(fā)送回去給openmv,請(qǐng)問(wèn)這是可以實(shí)現(xiàn)的嗎?也是通過(guò)UCA0TXBUF = UCA0RXBUF來(lái)進(jìn)行的嗎?
//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")
|
|