Part Number: MSP432P401R
Tool/software: Code Composer Studio
Good afternoon,
I'm trying to program my MSP432 to command a SIM808 GSM module to send a regular text message SMS to a phone number using UART communication.
My GSM module blinks as if it has set a connection with the network so I believe my problem is with the coding.
This is the code I am trying to use, however I believe my code is much more complicated than it must. I would appreciate help fixing my code or providing a sample code that could help me send a SMS.
#include "msp.h"
void GSM_Init(void);
void Number (char *num);
void Send (char *msg);
int main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | // Stop watchdog timer
WDT_A_CTL_HOLD;
CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
CS->CTL0 = 0; // Reset tuning parameters
CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz (nominal, center of 8-16MHz range)
CS->CTL1 = CS_CTL1_SELA_2 | // Select ACLK = REFO
CS_CTL1_SELS_3 | // SMCLK = DCO
CS_CTL1_SELM_3; // MCLK = DCO
CS->KEY = 0; // Lock CS module from unintended accesses
// Configure UART pins
P3->SEL0 |= BIT2 | BIT3; // set 2-UART pin as secondary function
// Configure UART
EUSCI_A2->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
EUSCI_A2->CTLW0 = EUSCI_A_CTLW0_SWRST | // Remain eUSCI in reset
EUSCI_B_CTLW0_SSEL__SMCLK; // Configure eUSCI clock source for SMCLK
// Baud Rate calculation
// 12000000/(16*9600) = 78.125
// Fractional portion = 0.125
// User's Guide Table 21-4: UCBRSx = 0x10
// UCBRFx = int ( (78.125-78)*16) = 2
EUSCI_A2->BRW = 78; // 12000000/16/9600
EUSCI_A2->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |
EUSCI_A_MCTLW_OS16;
EUSCI_A2->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI
EUSCI_A2->IFG &= ~EUSCI_A_IFG_RXIFG; // Clear eUSCI RX interrupt flag
EUSCI_A2->IE = 0; // Enable USCI_A0 RX interrupt
// Enable global interrupt
// __enable_irq();
// Enable eUSCIA0 interrupt in NVIC module
NVIC->ISER[0] = 1 << ((EUSCIA0_IRQn) & 31);
// Enable sleep on exit from ISR
SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
// Ensures SLEEPONEXIT occurs immediately
////// __DSB();
// Enter LPM0
// __sleep();
// __no_operation(); // For debugger
while(1){
GSM_Init();
Number("+526565555303");
Send("BLA");
while(1);
}
}
void GSM_Init(void){
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'A';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'T';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 0x0D;
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 0x0A;
__delay_cycles(24000000);
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'A';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'T';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = '+';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'C';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'M';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'G';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'F';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = '=';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = '1';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 0X0D;
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 0X0A;
__delay_cycles(6000000);
}
void Number (char* num){
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'A';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'T';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = '+';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'C';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'M';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'G';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 'S';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = '=';
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = '"';
int x = 0;
for( x = 0; ( num[x] !='\0') ; x++){
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = num[x];
}
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = '"';
EUSCI_A2->TXBUF = 0X0D;
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 0X0A;
__delay_cycles(6000000);
}
void Send (char * msg){
int x = 0;
while(msg[x] != '\0'){
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = msg[x];
x++;
}
while(!(EUSCI_A2->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A2->TXBUF = 26;
__delay_cycles(6000000);
}