Hi,
I am using "Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux" , I have set up the msp430-gcc toolchain and able to run the blinky program on my msp430f2274. Now, I am moving to application development and before doing so, I'd like to setup the UART for debugging purpose. However, for some reason, I am unable to get the byte on the terminal. I have cross checked through my code and did not find any loopholes that may be causing this issue. Please find my source codes below,
1. gpio.c
/* Include's */ #include <msp430f2274.h> /* Definitions */ #define MAX_PIN_NO_INVALID 255 /**************************************************************** * Function Name : gpio_configure * Description : Configures GPIO as I/O * Returns : 0 = Success -1 = Fail * Params : @port_no = Port No. @pins_no = Pins in the port to configure ****************************************************************/ signed char gpio_configure (unsigned char port_no, unsigned char pins_no) { signed char ret = 0; if (pins_no > MAX_PIN_NO_INVALID) port_no = 0; switch (port_no) { case 1: P1DIR = pins_no; break; case 2: P2DIR = pins_no; break; case 3: P3DIR = pins_no; break; case 4: P4DIR = pins_no; break; default: ret = -1; } return (ret); } /**************************************************************** * Function Name : gpio_write * Description : Sets gpio HIGH or LOW * Returns : 0 = Success -1 = Fail * Params : @port_no = Port No. @pins_no = Pins to set HIGH or LOW ****************************************************************/ signed char gpio_write (unsigned char port_no, unsigned char pin_no_val) { signed char ret = 0; if (pin_no_val > MAX_PIN_NO_INVALID) port_no = 0; switch (port_no) { case 1: P1OUT = pin_no_val; break; case 2: P1OUT = pin_no_val; break; case 3: P1OUT = pin_no_val; break; case 4: P1OUT = pin_no_val; break; default: ret = -1; } return (ret); } /**************************************************************** * Function Name : gpio_read * Description : Reads the status of the gpio * Returns : 0 or 1 = Success -1 = Fail * Params : @port_no = Port No. @pins_no = Pin to be read ****************************************************************/ signed char gpio_read (unsigned char port_no, unsigned char pin_no) { signed char ret = 0; if ((pin_no == BIT0) || (pin_no == BIT1) || (pin_no == BIT2) || (pin_no == BIT3) || (pin_no == BIT4) || (pin_no == BIT5) || (pin_no == BIT6) || (pin_no == BIT7)) { /* Do Nothing */ } else { port_no = 0; } switch (port_no) { case 1: ret = P1IN & pin_no; break; case 2: ret = P2IN & pin_no; break; case 3: ret = P3IN & pin_no; break; case 4: ret = P4IN & pin_no; break; default: ret = -1; } return (ret); } /**************************************************************** * Function Name : gpio_mux * Description : Select GPIO alternate function * Returns : 0 = Success -1 = Fail * Params : @port_no = Port No. @pins_no = Pins to mux ****************************************************************/ signed char gpio_mux (unsigned char port_no, unsigned char pins_no) { signed char ret = 0; if (pins_no > MAX_PIN_NO_INVALID) port_no = 0; switch (port_no) { case 1: P1SEL|= pins_no; break; case 2: P2SEL|= pins_no; break; case 3: P3SEL|= pins_no; break; case 4: P4SEL|= pins_no; break; default: ret = -1; } return (ret); }
2. uart.c
/* Lib Includes */ #include <msp430f2274.h> #include "gpio_driver.h" /* Definitions */ #define UARTA0_PORT_NO 0x03 /* P3 */ #define UARTA0_PINS_MUX_VAL 0x30 /* P3.4(TXD) & P3.5(RXD) */ /* Local Function Declarations */ static void uart_mux_pins (); static void uart_configure (); /*----------------Function Definitions-----------------*/ static void uart_mux_pins () { signed char ret; if (ret = gpio_mux(UARTA0_PORT_NO, UARTA0_PINS_MUX_VAL) == -1) { /* Debug Code - LED blinks 5 times indicating a fault */ } else { /* Debug Code - LED blinks 2 times indicating all good */ } } static void uart_configure () { /* Register Settings */ UCA0CTL0 = 0x00; UCA0CTL1 |= UCSWRST + UCSSEL_2; UCA0BR0 = 0x65; UCA0BR1 = 0x03; UCA0MCTL = UCBRS_1; // UCA0STAT |= UCLISTEN; UCA0CTL1 &= ~UCSWRST; /* Enable TXD and RXD Interrupts */ IE2 |= UCA0TXIE; IE2 |= UCA0RXIE; /* Enable Global/Maskable Interrupts */ _BIS_SR (GIE); } void uart_init () { uart_mux_pins (); uart_configure (); } //-----------------------------------------------------------------------// // Transmit and Receive interrupts // //-----------------------------------------------------------------------// #pragma vector = USCIAB0TX_VECTOR __interrupt void TransmitInterrupt (void) { gpio_write (0x01,0x01); } #pragma vector = USCIAB0RX_VECTOR __interrupt void ReceiveInterrupt (void) { IFG2 &= ~UCA0RXIFG; }
3. main.c
/* Lib Includes */ #include <msp430f2274.h> #include "gpio_driver.h" #include "uart_driver.h" int main () { signed char ret = 0; WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog if (CALBC1_1MHZ == 0xFF) // If calibration constant erased { while (1); // do not load, trap CPU!! } DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_8MHZ; // Set range DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation if (ret = gpio_configure (1, 0x01) == -1) { /* Debug Code - LED blinks 5 times indicating a fault */ } uart_init (); UCA0TXBUF = 'A'; }
Currently, I am just looking to send a byte from the msp to the terminal (/dev/ttyAMC0). I am using the MSP430 Ez430-RF2500 Development Tool. I tried the loopback test as well, did not work. Any support to getting this to work would be helpful.Thanks.
-Vinay Divakar