Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SerialPort & CCS String Communication

I'm trying to send/receive a string through C#, in C# i just do:

SerialPort.WriteLine("A6");

but in CCS, if i try sending a string char after char it does not work at all, neither with ReadLine nor with ReadExisting! This is what i have tried creating an array, so that everytime we enter the RXBUFF pragma, we add the received char to the array, until the array is full (i randomly defined the array size to be 2, which means we deal with 2-char-length strings), and eventually send the string by sending char after char:

 #pragma vector = USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)

if(__even_in_range(UCA1IV,18) == 0x02){          // Vector 2 - RXIFG
    if(counter==0)
    {
        Data[0]=UCA1RXBUF;
        counter++;
    }
    else
    {
        Data[1]=UCA1RXBUF;
        counter=0;
        UCA1TXBUF=Data[0];
        while(!(UCA1IFG & UCTXIFG)); // until UCTXBUF1 is empty
        UCA1TXBUF=Data[1];
    }
}

in C#:

 listBox2.Items.Add(SerialPort.ReadExisting());

i get non-sense text, like : ??A??? sometimes : ????A? etc.., but with:

listBox2.Items.Add(SerialPort.ReadLine());

in the first time i press the Send button which sends the "A6", i get nothing, the second time i get non-sense aswell , just like the ReadExisting behavior.

by the way, even if i try to send the string in the easiest way (without array and conditions), i mean like this:

#pragma vector = USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
        UCA1TXBUF='A';
        while(!(UCA1IFG & UCTXIFG));  // until UCTXBUF1 is empty
        UCA1TXBUF='6';

i also get inconsistent items in the listbox.

However, if i do this:

#pragma vector = USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
UCA1TXBUF=UCA1RXBUF;

i do get "A6" in the listbox and everything just work fine (with ReadLine and ReadExisting)! could anyone just tell me why this is happening?

like image 384
Renya Karasuma Avatar asked Jul 21 '14 19:07

Renya Karasuma


1 Answers

I'v just neutralized the Parity bit, everything works now, Thank you all!

like image 75
Renya Karasuma Avatar answered Oct 09 '22 09:10

Renya Karasuma