Ljubivoj Cvitas
/
SerialMBEDtoMSP430
TVZ test
Diff: main.cpp
- Revision:
- 4:4620184bbb1f
- Parent:
- 3:a4a5d9c0bc13
- Child:
- 5:77ff08b129c0
--- a/main.cpp Tue Jan 21 18:40:20 2014 +0000 +++ b/main.cpp Fri Feb 07 12:12:33 2014 +0000 @@ -4,96 +4,121 @@ DigitalOut red_led(LED4); //red led DigitalOut green_led(LED3); //green led DigitalOut RXDIN (LED1); -DigitalOut strobe(p7); //a strobe to trigger the scope + DigitalIn switch_ip1(p5); DigitalIn switch_ip2(p6); +DigitalIn switch_ip3(p7); +DigitalIn switch_ip4(p8); + Serial pc(USBTX, USBRX); char header_read ; //first byte we will send char param_ads; // parameter address -char recd_val; //the received value +char recd_val; //the received value int valueADC; char Outbuff[12]; char Inbuff[12]; -int valueSensA, valueSensB; - -int main() { - async_port.baud(9600); //set baud rate to 9600 (ie default) - //accept default format, of 8 bits, no parity - while (1){ - //Set up the word to be sent, by testing switch inputs - header_read=0x10; //set up a recognisable output pattern - param_ads = 0; - if (switch_ip1==1) - param_ads =param_ads | 0x01; //OR in lsb - if (switch_ip2==1) - param_ads =param_ads | 0x02; //OR in next lsb - - strobe =1; //short strobe pulse - wait_us(10); - strobe=0; - - valueADC = 0x0302; - Outbuff[0] = valueADC; - Outbuff[1] = valueADC >> 8; - /* - while (async_port.writeable()==0); //is there a place to write? - async_port.putc(Outbuff[1]); //transmit switch_word - while (async_port.writeable()==0); //is there a place to write? - async_port.putc(Outbuff[0]); //transmit switch_word - */ - while (async_port.writeable()==0); //is there a place to write? - async_port.putc(header_read); //transmit haeder - while (async_port.writeable()==0); //is there a place to write? - async_port.putc(param_ads); //transmit parameter address - - - - if (async_port.readable()==1){ //is there a character to be read? - Inbuff[0] = async_port.getc(); //if yes, t - } - if (async_port.readable()==1){ //is there a character to be read? - Inbuff[1] = async_port.getc(); //if yes, t - } - if (async_port.readable()==1){ //is there a character to be read? - Inbuff[2] = async_port.getc(); //if yes, t - } - if (async_port.readable()==1){ //is there a character to be read? - Inbuff[3] = async_port.getc(); //if yes, t - - if (async_port.readable()==1){ //is there a character to be read? - Inbuff[4] = async_port.getc(); //if yes, t - } - if (async_port.readable()==1){ //is there a character to be read? - Inbuff[5] = async_port.getc(); //if yes, t - } - if (async_port.readable()==1){ //is there a character to be read? - Inbuff[6] = async_port.getc(); //if yes, t - } - - RXDIN = 1; - } - /*if (async_port.readable()==1){ //is there a character to be read? - recd_val=async_port.getc(); //if yes, t - RXDIN = 1; - }*/ - wait(0.01); -//set leds according to incoming word from slave - red_led=0; //preset both to 0 - green_led=0; - recd_val=recd_val&0x03; //AND out unwanted bits - if (recd_val==1) - red_led=1; - if (recd_val==2) - green_led=1; - if (recd_val==3){ - red_led=1; - green_led=1; - } - wait(1); - RXDIN = 0; - valueSensA = Inbuff[2]+ Inbuff[3]*256; - valueSensB = Inbuff[4]+ Inbuff[5]*256; - pc.printf("SensA: %d SensB: %d \n\r", valueSensA, valueSensB); - } -} +int valueSensA, valueSensB, valueSensC, valueSensD; +float fAzimuthErr; +float fElevationErr; +unsigned char *pointnavar; + +int main() +{ + async_port.baud(9600); //set baud rate to 9600 (ie default) + switch_ip1.mode(PullUp); // Pull up internal resistor + switch_ip2.mode(PullUp); + switch_ip3.mode(PullUp); + switch_ip4.mode(PullUp); + + //accept default format, of 8 bits, no parity + while (1) { + + // read or write mode ? + if (switch_ip1==0) { + header_read=0x10; // read output pattern + if (switch_ip2==0) { + param_ads = 0; + } else { + param_ads = 1; + } + + /* + valueADC = 0x0302; + Outbuff[0] = valueADC; + Outbuff[1] = valueADC >> 8; */ + + while (async_port.writeable()==0); //is there a place to write? + async_port.putc(header_read); //transmit haeder + while (async_port.writeable()==0); //is there a place to write? + async_port.putc(param_ads); //transmit parameter address + + + + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[0] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[1] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[2] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[3] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[4] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[5] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[6] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[7] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[8] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[9] = async_port.getc(); //if yes, t + } + if (async_port.readable()==1) { //is there a character to be read? + Inbuff[10] = async_port.getc(); //if yes, t + } + + RXDIN = 1; + wait(1); + RXDIN = 0; + if (param_ads==0x00) { + valueSensA = Inbuff[2]+ Inbuff[3]*256; + valueSensB = Inbuff[4]+ Inbuff[5]*256; + valueSensC = Inbuff[6]+ Inbuff[7]*256; + valueSensD = Inbuff[8]+ Inbuff[9]*256; + pc.printf("SensA: %d SensB: %d SensC: %d SensD: %d \n\r", valueSensA, valueSensB, valueSensC, valueSensD); + } + if (param_ads==0x01) { + pointnavar = (unsigned char*) &fAzimuthErr; + for (int i=2; i<6; i++) { + *pointnavar = Inbuff[i]; + pointnavar++; + } + pointnavar = (unsigned char*) &fElevationErr; + for (int i=6; i<10; i++) { + *pointnavar = Inbuff[i]; + pointnavar++; + } + pc.printf("AZIMUT: %+3.0f ELEVATION; %+3.0f \n\r", fAzimuthErr, fElevationErr); + } + } // if (switch_ip1==0) + + else { + header_read=0x20; // write output pattern + param_ads = 2; // parameter to write + + + } // else + } // while(1) +} //main