SerialPort & CCS String Communication

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

SerialPort.WriteLine("A6"); 

but in CCS, if I try to send a char string after a char, it does not work at all, neither with ReadLine nor with ReadExisting! This is what I tried to create an array, so every time we enter the pragma RXBUFF, we add the resulting char array to the array until the array is full (I accidentally determined the size of the array to 2, which means that we are dealing with 2- char -longed strings) and end up sending 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 the text without meaning, for example: ?????? sometimes:???? etc., but with:

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

the first time I press the "Send" button, which sends "A6", I get nothing, the second time I get non-meaning, like ReadExisting behavior.

By the way, even if I try to send a string in the simplest way (without an 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 list.

However, if I do this:

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

I get "A6" in the list and everything just works fine (with ReadLine and ReadExisting)! can anyone just tell me why this is happening?

+6
source share
2 answers

I just neutralized the parity bit, everything works now, thanks everyone!

+1
source

This means that you do not have to wait for the TX flag inside the RX ISR. The RX interrupt routine should just populate the FIFO buffer (byte queue) so you can parse the contents elsewhere (main routine?), And then create an answer when necessary.

The pseudocode for the RX ISR should look something like this:

 #pragma vector = USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) FIFO_Enqueue(&RxBuffer, UCA1RXBUF); 

And somewhere inside the main() loop, you can parse its contents:

 while (1) { // find the first occurrence of "A6" and dequeue it if (FIFO_StartsWith(&RxBuffer, "A6") SendResponse(); } 
0
source

Source: https://habr.com/ru/post/972606/


All Articles