Other Parts Discussed in Thread: MSP430FR2311
Tool/software:
I'm a student currently working on a project involving the MSP430FR5994 microcontroller. My task is to implement UART communication to send data from the microcontroller to my PC. To verify my C code before implementation.
The reception works perfectly when I send characters, but I encounter issues when sending integers. Surprisingly, I don't receive anything at all, and even the LED that indicates data transmission doesn't toggle.
Here's the C code I'm using:
#include <msp430.h>
#include <stdint.h>
// Déclarations des fonctions
void initClock(void);
void initUART(void);
void initPort(void);
void sendBuffer(void);
int main(void) {
// Stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
// Initialisation des périphériques
initClock();
initPort();
initUART();
while (1) {
// Send a predefined buffer via UART
sendBuffer();
P1OUT ^= BIT0; // Toggle LED to indicate sending data
__delay_cycles(1000000); // Add a delay to avoid too fast a loop
}
return 0;
}
// Initialisation de l'horloge
void initClock(void) {
CSCTL0_H = CSKEY >> 8; // Déverrouillage du module CS
CSCTL1 = DCOFSEL_6; // Sélection de DCO à 8 MHz (selon la documentation MSP430)
CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK; // Configuration des sources d'horloge
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Réglage des diviseurs d'horloge
CSCTL0_H = 0; // Verrouiller le module CS
}
// Initialisation de l'UART
void initUART(void) {
UCA0CTLW0 = UCSWRST; // Mise à la réinitialisation du module UART
P2SEL0 &= ~(BIT0 | BIT1); // Configuration des broches P2.0 et P2.1
P2SEL1 |= (BIT0 | BIT1);
UCA0CTLW0 |= UCSSEL__SMCLK; // Sélection de SMCLK comme source d'horloge UART
UCA0BRW = 52; // Configuration du débit en bauds à 9600 bauds
UCA0MCTLW = UCOS16 | UCBRF_1 | 0x49; // Configuration des paramètres de modulation
UCA0CTLW0 &= ~UCSWRST; // Sortie de la réinitialisation
UCA0IE |= UCRXIE; // Activation des interruptions de réception UART
}
// Initialisation des ports GPIO
void initPort(void) {
P1OUT = 0x00;
P1DIR = 0xFF;
P1OUT |= BIT0;
P2OUT = 0x00;
P2DIR = 0xFF;
P3OUT = 0x00;
P3DIR = 0xFF;
P4OUT = 0x00;
P4DIR = 0xFF;
P5OUT = 0x00;
P5DIR = 0xFF;
P6OUT = 0x00;
P6DIR = 0xFF;
P7OUT = 0x00;
P7DIR = 0xFF;
P8OUT = 0x04;
P8DIR = 0xFF;
P9OUT = 0x00;
P9DIR = 0xFF;
PAOUT = 0x00;
PADIR = 0xFF;
PBOUT = 0x00;
PBDIR = 0xFF;
PCOUT = 0x00;
PCDIR = 0xFF;
PDOUT = 0x00;
PDDIR = 0xFF;
PEOUT = 0x00;
PEDIR = 0xFF;
PJOUT = 0x00;
PJDIR = 0xFF;
P2SEL0 &= ~(BIT0 | BIT1);
P2SEL1 |= (BIT0 | BIT1);
}
// Function to send a predefined buffer via UART
void sendBuffer(void) {
// Data buffer to send
uint8_t buffer[] = {0x01, 0x02, 0x03, 0x04, 0x05};
// Send buffer via UART
int i;
for (i = 0; i < sizeof(buffer); i++) {
// Wait until transmission register is ready
while (!(UCA0IFG & UCTXIFG));
// Send buffer element
UCA0TXBUF = buffer[i];
// Wait until transmission is complete
while (UCA0STATW & UCBUSY);
}
}
I would appreciate any insights into what might be causing this issue and how I can rectify it. Additionally, if you have any suggestions or improvements for my C code, I'd be grateful for your input.
Thank you all for your time and assistance!