Hello All
Am using MSP432 development board, have successfully able to identify the interrupts and save them in the buffer. But when i try to read the text i fail to compare it with the predefined text.
Another question, is it ok to use __delay_cycles() for delay ??? If not ok why and what would be preffered over __delay_cycles()??
Ex: From the Interrupt i would send series of characters like " Turn On" or " Turn Off" or " Status"
In the code i compare with the buffer the above mentioned predefined text. but it does not identify.
Please suggest where am going wrong.
/* DriverLib Includes */
#include "driverlib.h"
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
#define BUFF_SIZE 16
static volatile uint8_t buff[BUFF_SIZE];
static volatile uint32_t buff_indx_filling = 0;
static volatile uint32_t buff_indx_emptying = 0;
static volatile bool buff_is_empty = true; // true: empty, false: full
void flash_once(void)
{
__delay_cycles(50000);
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
}
void flash_twice(void)
{
__delay_cycles(50000);
GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN2);
}
/* UART Configuration Parameter. These are the configuration parameters to
* make the eUSCI A UART module to operate with a 9600 baud rate. These
* values were calculated using the online calculator that TI provides
* at:
*software-dl.ti.com/.../index.html
*/
const eUSCI_UART_Config uartConfig =
{
EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
78, // BRDIV = 78
2, // UCxBRF = 2
0, // UCxBRS = 0
EUSCI_A_UART_NO_PARITY, // No Parity
EUSCI_A_UART_LSB_FIRST, // LSB First
EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
EUSCI_A_UART_MODE, // UART mode
EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling
};
int main(void)
{
/* Halting WDT */
MAP_WDT_A_holdTimer();
/* Selecting P1.2 and P1.3 in UART mode */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
/* Setting DCO to 12MHz */
CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);
/* Configuring UART Module */
MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig);
/* Enable UART module */
MAP_UART_enableModule(EUSCI_A0_MODULE);
/* Enabling interrupts */
MAP_UART_enableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT);
MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
MAP_Interrupt_enableSleepOnIsrExit();
MAP_Interrupt_enableMaster();
while(1)
{
MAP_PCM_gotoLPM0();
}
}
void euscia0_isr(void)
{
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_MODULE);
MAP_UART_clearInterruptFlag(EUSCI_A0_MODULE, status);
if(status & EUSCI_A_UART_RECEIVE_INTERRUPT)
{
if (buff_is_empty == true)
{
flash_once();
buff[buff_indx_filling++] = MAP_UART_receiveData(EUSCI_A0_MODULE);
if (buff_indx_filling == BUFF_SIZE)
{
MAP_UART_transmitData(EUSCI_A0_MODULE,'L');
if (buff == "TURNON" || "TURNOFF" )
{
if (buff == "TURNON")
{
MAP_UART_transmitData(EUSCI_A0_MODULE,'S');
}
if (buff == "TURNOFF")
{
MAP_UART_transmitData(EUSCI_A0_MODULE,'N');
}
if (buff[buff_indx_filling] == "STATUS")
{
MAP_UART_transmitData(EUSCI_A0_MODULE,'J');
}
buff_is_empty = true;
buff_indx_filling = 0;
MAP_UART_transmitData(EUSCI_A0_MODULE,'Q');
}
}
else
{
MAP_UART_transmitData(EUSCI_A0_MODULE,'Z');
}
}
}