Part Number: MSP432P401R
Hello,
I want to send a data frame through the UART. I have two MSP432 : the one, the master, sends a data frame which is read by the slave. This slave extracts data from the frame and when the data is correct, I want the slave to answer to the master.
For the first part (master -> slave), no problem, the data is sent. Then the part where the slave tests the data is good too. The problem is the send back to the master. I use the same code than for the master, but when the program of the slave is in freerun, the data frame sent is not complete (two last characters are not sent - there is OxFF instead).
I would think that there is a problem in my code, but when I put a stop point and sends the character one after the other, the data frame is completely sent. It's only when I let the program in freerun that there is a problem.
So I thought about an interrupt pending while I'm sending my frame, but I turned off all of them except for the sending, and the pb is the same...
Here is my slave code. In the while(1), I test the data received :
if (G_uint32Data_trame == 0x41464431) // If data received is good (AFD1)
{
encodage_trame_retour_ADC_vers_maitre(); // Function that sends the data frame as an answer to the master
EUSCI_A1->IFG |= EUSCI_A_IFG_TXIFG;// Clear TXIFG flag
EUSCI_A1->IE |= EUSCI_A_IE_TXIE; // Enable TX interrupt
}
Then I call the function "encodage_trame_retour_ADC_vers_maitre":
void encodage_trame_retour_ADC_vers_maitre(void)
{
snap_t snap;
snap_init(&snap);
snap_set_local_address(&snap,G_uint8Adresse_locale);
snap_set_peer_address(&snap,1);
uint8_t in[]={'O','p'}; // Ask For Data, capteur 1
size_t in_size = sizeof(in)/sizeof(in[0]);
size_t out_size = snap_encode_bound(&snap,in_size);
G_uint8Longueur_trame = out_size ; // Variable globale pour dire au programme d'envoi quel nombre d'octets fait la trame codée
size_t out_pos = 0;
snap_encode(&snap,in,in_size,G_uint8Trame_retour_ADC_vers_maitre,&out_pos,out_size);
out_pos --;
}
This function make a data frame with "Op" as data inside.
Then I authorized the interrupts TX :
EUSCI_A1->IFG |= EUSCI_A_IFG_TXIFG;// Clear TXIFG flag
EUSCI_A1->IE |= EUSCI_A_IE_TXIE; // Enable TX interrupt
And here is my interrupt routine :
void eUSCIA1IsrHandler(void)
{
if (UCA1IFG & UCRXIFG)
{
G_uint8ReceptionFlag = 1;
while(!(UCA1IFG&UCRXIFG));
G_uint8Tableau_reception_trame[G_uint8Compteur_octet_trame] = UCA1RXBUF;
}
UCA1IFG &=~ UCRXIFG;
if (UCA1IFG & UCTXIFG)
{
while (G_uint8Compteur_octet_trame_2 <= (G_uint8Longueur_trame-1)) // G_uint8Longueur_trame contient le nombre total d'octets de la trame codée ; s'adapte donc automatiquement au nombre de data
{
while(!(UCA1IFG&UCTXIFG)); // On attend que le buffer de transmission soit prêt
EUSCI_A1->TXBUF = G_uint8Trame_retour_ADC_vers_maitre[G_uint8Compteur_octet_trame_2]; // Envoi car après car
G_uint8Compteur_octet_trame_2 ++;
}
G_uint8Longueur_trame = 0;
G_uint8Compteur_octet_trame_2 = 0;
}
UCA1IFG &=~ UCTXIFG;
}
Once again, when I put a stop point (debug point) after the end of the sending (for example in front of G_uint8Compteur_octet_trame_2 = 0; (see just above), the data frame is complete. When I freerun the program, or when I put the debug point far away, the data frame is not complete and sends a right beginning but sends 0xFF instead of Op.
Thank you in advance
Sylvain