Tool/software: Code Composer Studio
Hi I am trying to send a character through the serial communication port using the code given below. The code is used to control the speed of a stepper motor connected to Msp432P401R. I am trying to send a character "B" over to putty on pressing button P1.1 .Upon button press the direction of the motor changes and it is indicated by the character "B". At present I am able to transmit the data but it is being received in putty as some null value or some other character. I have checked the baud rate , parity bits and stop bits. its all seems to be correct.
#include "msp432.h"
volatile unsigned int i;
//char TXData = '1';
int main(void) {
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // Stop WDT
// GPIO Setup
P4->OUT &= ~BIT6; //Direction of Motor
P4->DIR |= BIT6; //Set Direction of the motor
P1->OUT = BIT1;
P1->REN = BIT1; // Enable pull-up resistor (P1.1 output high)
P1->IFG = 0; // Clear all P1 interrupt flags
P1->IE = BIT1; // Enable interrupt for P1.1
P1->IES = BIT1; // Interrupt on high-to-low transition
P2->SEL0 |= 0x80;
P2->SEL1 &= ~0x80;//PWM
P2->DIR |= 0x80;
TIMER_A0->CCR[0] = 10000 - 1; /* PWM Period */
TIMER_A0->CCTL[4] = 0xE0; /* CCR4 reset/set mode */
TIMER_A0->CTL = 0x0214; /* use SMCLK, count up, clear TA0R register */
P5->SEL1 |= BIT4; // Configure P5.4 for ADC
P5->SEL0 |= BIT4;
//Ports for UART and LED
P1->DIR |= BIT0;
P1->OUT &= ~BIT0; // P1.0 LED
// Configure UART pins
P1->SEL0 |= BIT2 | BIT3; // set 2-UART pin as second function
//UART config
EUSCI_A0->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
EUSCI_A0->CTLW0 = EUSCI_A_CTLW0_SWRST |EUSCI_B_CTLW0_SSEL__SMCLK; // Remain eUSCI in reset and Configure eUSCI clock source for SMCLK
// EUSCI_A0->BRW = 1; // Using baud rate calculator
// EUSCI_A0->MCTLW = (10 << EUSCI_A_MCTLW_BRF_OFS) |EUSCI_A_MCTLW_OS16;
// EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST;// Initialize eUSCI
// EUSCI_A0->IE |= EUSCI_A_IE_RXIE; // Enable USCI_A0 RX interrupt
EUSCI_A0->BRW = 78; // 12000000/16/9600
EUSCI_A0->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |EUSCI_A_MCTLW_OS16;
EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI
EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG; // Clear eUSCI RX interrupt flag
EUSCI_A0->IE |= EUSCI_A_IE_RXIE; // Enable USCI_A0 RX interrupt
// Enable global interrupt
__enable_irq(); // Enable ADC interrupt in NVIC module
NVIC->ISER[0] = 1 << ((ADC14_IRQn) & 31);
// Sampling time, S&H=16, ADC14 on
ADC14->CTL0 = ADC14_CTL0_SHT0_2 | ADC14_CTL0_SHP | ADC14_CTL0_ON;//,Pulse sample mode is selected,core is ready to power up when a valid conversion is triggered.
ADC14->CTL1 = ADC14_CTL1_RES_2; // Use sampling timer, 12-bit conversion results
ADC14->MCTL[0] |= ADC14_MCTLN_INCH_1; // A1 ADC input select; Vref=AVCC
ADC14->IER0 |= ADC14_IER0_IE0; // Enable ADC conv complete interrupt
ADC14->IER0 = ADC14_IER0_IE0; // Enable ADC14IFG.0
SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; // Wake up on exit from ISR
// Ensures SLEEPONEXIT takes effect immediately
__DSB();
while (1)
{
//P1->OUT &= ~BIT0;
//printf("%d",TXData);
// for (i = 200; i > 0; i--); // Delay
//Start sampling/conversion
ADC14->CTL0 |= ADC14_CTL0_ENC | ADC14_CTL0_SC;
__sleep();
__no_operation(); // For debugger
}
}
// ADC14 interrupt service routine
void ADC14_IRQHandler(void) {
volatile uint8_t temp;
if (ADC14->MEM[0] > 0x0F & ADC14->MEM[0] <= 0x7F) {
P4->OUT = 0x0000;
TIMER_A0->CCR[0] = 0;
TIMER_A0->CCR[4] = 0;
}
if (ADC14->MEM[0] > 0x7F & ADC14->MEM[0] <= 0xFF) {
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 50000 - 1;
TIMER_A0->CCR[4] = 50000 / 5;
}
else if (ADC14->MEM[0] > 0xFF & ADC14->MEM[0] <= 0x2FF) {
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 40000 - 1;
TIMER_A0->CCR[4] = 40000 / 3;
}
else if (ADC14->MEM[0] > 0x2FF & ADC14->MEM[0] <= 0x7FF) {
//P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 20000 - 1;
TIMER_A0->CCR[4] = 20000 / 2;
}
else if (ADC14->MEM[0] > 0x7FF & ADC14->MEM[0] <= 0xAFF) {
//P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 15000 - 1;
TIMER_A0->CCR[4] = 15000 / 1.5;
}
else if (ADC14->MEM[0] > 0xAFF & ADC14->MEM[0] <= 0xCFF) {
// P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 10000 - 1;
TIMER_A0->CCR[4] = 10000 / 1.2;
}
else if (ADC14->MEM[0] > 0xCFF & ADC14->MEM[0] <= 0xFFF) {
//P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
if(EUSCI_A0->IFG & EUSCI_A_IFG_RXIFG)
//temp = EUSCI_A0->RXBUF;
EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG;
P4->OUT ^= BIT6;
while(!(EUSCI_A0->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
EUSCI_A0->TXBUF = "B";
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 5000 - 1;
TIMER_A0->CCR[4] = 5000 / 1.1;
}
}