PuTTY data into MSP430 - c

I am attempting to program two MSP430s to essentially instant message through PuTTY, but cannot figure out how to get typed information onto the MSP430 without the debugger. I'm using CCS and it's an MSP430 F2274. I have one program in which the user inputs in morse code on the button on one MSP430 that successfully outputs to PuTTY off another MSP430 via the following method.
void displayString(char array[], char size) {
WDTCTL = WDTPW + WDTHOLD; // Disable WDT
DCOCTL = CALDCO_8MHZ; // Load 8MHz constants
BCSCTL1 = CALBC1_8MHZ; //
P3SEL |= 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 0x41; // 8MHz 9600
UCA0BR1 = 0x03; // 8MHz 9600
UCA0MCTL = UCBRS1; // Modulation UCBRSx = 2
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
int count;
for(count=0; count<size; count++){
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = array[count]; // TX -> RXed character
}
}
Can someone send code that does the reverse (types information onto MSP430) with a similar setup? thanks.

I used picocom:
$ picocom -r -b 9600 /dev/ttySxxxx
Code for UART initialization:
void uart_setup()
{
// Configure UART pins
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1);
// Configure UART 0
UCA0CTL1 |= UCSWRST; // perform reset
UCA0CTL1 = UCSSEL_1; // Set ACLK = 32768 as UCBRCLK
UCA0BR0 = 3; // 9600 baud
UCA0BR1 = 0;
UCA0MCTLW |= 0x5300; // 32768/9600 - INT(32768/9600)=0.41
// UCBRSx value = 0x53 (See UG)
UCA0CTL1 &= ~UCSWRST; // release from reset
//UCA0IE |= UCRXIE; // Enable RX interrupt
}
Override putchar():
int putchar(int c)
{
if (c == '\n') putchar('\r');
while (!(UCA0IFG & UCTXIFG));
UCA0TXBUF = c;
return 0;
}
And then you can simple call printf(...) to output text from the MSP430 to the serial port.

If you still want to leave putchar() and prtinf() for debug purpose - printing into debug window of debugger, then you can have separate read function:
unsigned char ReadByteUCA_UART(void)
{
//while ((IFG2&UCA0RXIFG)==0); // wait for RX buffer (full)
while(UCA0STAT&UCBUSY);
return (UCA0RXBUF);
}

Related

SPI Communication between STM32 and ADXL345

I am trying to use the SPI communication to read data from the ADXL345 accelerometer. I configured the different pins and SPI in master mode, and tried reading the x, y and z axis accelerations.
My issue is that the SPI readings are always 0. I tried debugging to find the issue and I realized that RXNE is never set even though I'm transmitting data and I don't really get why.
I'm using STM32F103 Board.
Here's my code:
#include "Driver_GPIO.h"
#include "stm32f10x.h"
uint8_t RxData[6];
int x,y,z;
float x_acc,y_acc,z_acc;
void GPIO_Config (void)
{
MyGPIO_Struct_TypeDef NSS={GPIOA,4,Out_OD}; // Output Open Drain
MyGPIO_Struct_TypeDef SCK={GPIOA,5,AltOut_Ppull}; // Alternate Output Push-Pull
MyGPIO_Struct_TypeDef MISO={GPIOA,6,In_Floating}; // Input Floating
MyGPIO_Struct_TypeDef MOSI={GPIOA,7,AltOut_Ppull}; // Alternate Output Push-Pull
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; //enable GPIOA clk
MyGPIO_Init(&NSS);
MyGPIO_Init(&SCK);
MyGPIO_Init(&MISO);
MyGPIO_Init(&MOSI);
}
void SPI_Enable (void)
{
SPI1->CR1 |= (SPI_CR1_SPE); // SPE=1, Peripheral enabled
}
void SPI_Disable (void)
{
SPI1->CR1 &= ~(SPI_CR1_SPE); // SPE=0, Peripheral Disabled
}
void CS_Enable (void)
{
GPIOA->BSRR |= GPIO_BSRR_BR9;
}
void CS_Disable (void)
{
GPIOA->BSRR |= GPIO_BSRR_BS9;
}
void SPI_Config(void){
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; // Enable SPI1 CLock
SPI1->CR1 |= SPI_CR1_CPOL| SPI_CR1_CPHA; // CPOL=1, CPHA=1
SPI1->CR1 |= SPI_CR1_MSTR; // Master Mode
SPI1->CR1 |= (SPI_CR1_BR_0)| (SPI_CR1_BR_1); // BR[2:0] = 400: fPCLK/16, PCLK2 = 72MHz, SPI clk = 3.375MHz
SPI1->CR1 &= ~SPI_CR1_LSBFIRST; // LSBFIRST = 0, MSB first
SPI1->CR1 |= (SPI_CR1_SSM) | (SPI_CR1_SSI); // SSM=1, SSI=1 -> Software Slave Management
SPI1->CR1 &= ~SPI_CR1_RXONLY; // RXONLY = 0, full-duplex
SPI1->CR1 &= ~SPI_CR1_DFF; // DFF=0, 8 bit data
SPI1->CR2 = 0;
}
void SPI_Transmission(uint8_t *data, int size){
uint8_t clear;
//check flag TxE //
int i=0;
while (i<size)
{
while (!((SPI1->SR)&(SPI_SR_TXE))){}; // buffer is empty
*(volatile uint8_t *)&SPI1->DR = data[i];
i++;
}
while (!((SPI1->SR)&(SPI_SR_TXE))){}; // buffer is empty
while (((SPI1->SR)&(SPI_SR_BSY))){}; // buffer not communicating
clear= SPI1->DR; // empty Overrun flag
clear= SPI1->SR;
}
void SPI_Receive (uint8_t *data,int size)
{
while (size)
{
while (((SPI1->SR)&(SPI_SR_BSY))) {}; // buffer not communicating
*(volatile uint8_t *)&SPI1->DR = 0; // dummy data
while (!((SPI1->SR) &(SPI_SR_RXNE))){};
// buffer is not empty
*data++= *(volatile uint8_t *)&SPI1->DR;
size--;
}
}
void adxl345_write (uint8_t address, uint8_t value)
{
uint8_t data[2];
data[0] = address|0x40; // multibyte write
data[1] = value;
CS_Enable (); // pull the cs pin low
SPI_Transmission (data,2); // write data to register
CS_Disable (); // pull the cs pin high
}
void adxl345_read (uint8_t address, uint8_t *RxData)
{
address |= 0x80; // read operation
address |= 0x40; // multibyte read
CS_Enable (); // pull the pin low
SPI_Transmission (&address,1); // send address
SPI_Receive (RxData,6); // receive 6 bytes data
CS_Disable ();; // pull the pin high
}
void adxl345_init (void)
{
adxl345_write (0x31, 0x01); // data_format range= +- 4g
adxl345_write (0x2d, 0x00); // reset all bits
adxl345_write (0x2d, 0x08); // power_cntl measure and wake up 8hz
}
int main(void)
{
GPIO_Config();
SPI_Config();
SPI_Enable();
adxl345_init();
do{
adxl345_read(0x32,RxData);
x = ((RxData[1]<<8)|RxData[0]); // DATA X0, X1
y = ((RxData[3]<<8)|RxData[2]); // DATA Y0, Y1
z = ((RxData[5]<<8)|RxData[4]); // DATA Z0, Z1
// Scale Factor for Xout, Yout and Zout is 7.8 mg/LSB for a +-4g, 10-bit resolution
// ==> multiply by 0.0078 to get real acceleration values
x_acc= x * 0.0078;
y_acc= y * 0.0078;
z_acc= z * 0.0078;
}while(1);
}
As already stated you have a lot of issues here
Why NSS pin is configured open-drain? Typically CS lines are push-pull. I don't know the schematics, but this is the first time I see an open-drain CS
In GPIO_Config NSS is pin 4, yet pin 9 is toggled from CS_Enable
If F1 series there is separate clocking bit for the alternate functions, it's not enabled
It is also weird that you are telling that RXNE is always zero and the readings returns zero. Your code should stuck in while loops if RXNE stays zero
I will not analyze magic numbers as I do not have time check every number in the RM. But you have many obvious issues.
Deley or readback is required after enabling the peripheral clock. You instantly set the registers which is wrong. Add __DSB(); or readback (for example (void)RCC->APB2ENR;). Same for all peripherals

UART Communication Between STM32F03 and ESP-8266-01

I'm attempting to get a smartphone app to communicate with an MCU (STM32F030R8). The step I'm currently on is getting the WiFi module to talk with the MCU. I'm able use the AT firmware to configure the ESP when using an Arduino Uno/PC terminal, but want to essentially do the same via the STM board.
When I load the code to the STM and use Tera Term to send data to the STM it should be able to send AT commands to the ESP, but it isn't working. Right now I'm at a loss as to why this isn't working. I'm looking for pointers on the code that I've probably missed or other principles I've overlooked/am unaware of.
I've searched around on the internet the past couple days and haven't come up with much that helps. This is effectively the sum of my experience with C. Thanks for your help!
The hardware is set up as follows...
STM32 ESP
PA10 TX
PA9 RX
3.3V VCC
3.3V CH_PD
GND GND
UNO ESP
TX TX
RX RX
3.3V VCC
3.3V CH_PD
GND GND
The code I've frankenstein'd together is below. I'm using Keil uVision 5.
#include "stm32f0xx.h"
#include <stdio.h>
#include <string.h>
void USART1_Init(void);
void USART2_Init(void);
void USART1_Write(char ch[]);
char USART1_Read(void);
int main(void)
{
// disable the interrupt detection
__disable_irq();
RCC->AHBENR |= 0x00020000; // enable port A clock
GPIOA->MODER |= 0x00000400; // set mode for PA5
USART1_Init();
USART2_Init();
char strCommand[50];
NVIC_EnableIRQ(USART1_IRQn);
__enable_irq();
printf("\r\nInterface for ESP8266 AT commands.\r\n");
printf("Please enter the AT command: ");
gets(strCommand);
USART1_Write(strCommand);
printf("\r\n");
while (1);
}
// write data to the peripheral via USART1
void USART1_Write(char ch[])
{
// wait while the tx buffer is empty
while (!(USART1->ISR & 0x00000080));
for (int i = 0; i < strlen(ch); i++)
{
USART1->TDR = (ch[i] & 0xFF);
}
USART1->TDR = 0x0000000D;
USART1->TDR = 0x0000000A;
}
// read data from the peripheral via USART1
char USART1_Read(void)
{
// wait while the rx buffer is empty
while (USART1->ISR & 0x00000020);
return USART1->RDR;
}
// write data to the PC via USART2
int USART2_Write(int ch)
{
// wait while the tx buffer is empty
while (!(USART2->ISR & 0x00000080));
USART2->TDR = (ch & 0xFF);
return ch;
}
// read data from the PC via USART2
int USART2_Read(void)
{
// wait while the rx buffer is empty
while (!(USART2->ISR & 0x00000020));
return USART2->RDR;
}
// initialize USART1
void USART1_Init(void)
{
RCC->APB2ENR |= 0x00004000; // enable USART1 clock
GPIOA->AFR[1] |= 0x00000110; // set AF1 to PA9, PA10
GPIOA->MODER |= 0x00280000; // define GPIO modes to alternate function for PA9, PA10
USART1->BRR = 0x00000341; // set the baud rate, 9600 # 8MHz
USART1->CR1 = 0x0000002C; // enable te, re, and rx interrupt
USART1->CR1 |= 0x00000001; // enable ue
}
// initialize USART2
void USART2_Init(void)
{
RCC->APB1ENR |= 0x00020000; // enable USART2 clock
GPIOA->AFR[0] |= 0x00001100; // set AF1 to PA2, PA3
GPIOA->MODER |= 0x000000A0; // define GPIO modes to alternate function for PA2, PA3
USART2->BRR = 0x00000341; // set the baud rate, 9600 # 8MHz
USART2->CR1 = 0x0000000C; // enable te and re
USART2->CR1 |= 0x00000001; // enable ue
}
// handle the USART1 interrupt event
void USART1_IRQHandler(void)
{
char c;
if (USART1->ISR & 0x00000020)
{
c = USART1->RDR;
//GPIOA->ODR ^= 0x00000020; // toggle the PA5 state
printf("%c", c);
}
}
// implement stdin/stdout/stderr functionality
struct __FILE{int handle;};
FILE __stdin = {0};
FILE __stdout = {1};
FILE __stderr = {2};
int fgetc(FILE *f)
{
int c;
c = USART2_Read();
if (c == '\r')
{
USART2_Write(c);
c = '\n';
}
USART2_Write(c);
return c;
}
int fputc(int c, FILE *f)
{
return USART2_Write(c);
}
EDIT:
I've modified the code a bit and kept trying. When attempting to change the broadcasted network name/password (it didn't work) it now replies with the first two typed characters in the command consistently and after a moment put forth the gibberish at looks like it should have been summoned with an "AT+GMR" command. The following code is what was uploaded to the device. Any thoughts on how this could have happened? Thanks!
#include "stm32f0xx.h"
#include <stdio.h>
#include <string.h>
void USART1_Init(void);
void USART2_Init(void);
void USART1_Write(char ch[]);
char USART1_Read(void);
int main(void)
{
// disable the interrupt detection
__disable_irq();
RCC->AHBENR |= 0x00020000; // enable port A clock
GPIOA->MODER |= 0x00000400; // set mode for PA5
USART1_Init();
USART2_Init();
char strCommand[50];
NVIC_EnableIRQ(USART1_IRQn);
__enable_irq();
printf("\r\nInterface for ESP8266 AT commands.\r\n");
printf("Please enter the AT command: ");
gets(strCommand);
USART1_Write(strCommand);
printf("\r\n");
while (1);
}
// write data to the peripheral via USART1
void USART1_Write(char ch[])
{
// wait for the tx buffer to be empty
while (!(USART1->ISR & 0x00000080));
for (int i = 0; i < strlen(ch); i++)
{
USART1->TDR = (ch[i] & 0xFF);
}
// USART1->TDR = '\r';
// USART1->TDR = '\n';
}
// read data from the peripheral via USART1
char USART1_Read(void)
{
// wait while the rx buffer is empty
while (USART1->ISR & 0x00000020);
return USART1->RDR;
}
// write data to the PC via USART2
int USART2_Write(int ch)
{
// wait while the tx buffer is empty
while (!(USART2->ISR & 0x00000080));
USART2->TDR = (ch & 0xFF);
return ch;
}
// read data from the PC via USART2
int USART2_Read(void)
{
// wait while the rx buffer is empty
while (!(USART2->ISR & 0x00000020));
return USART2->RDR;
}
// initialize USART1
void USART1_Init(void)
{
RCC->APB2ENR |= 0x00004000; // enable USART1 clock
GPIOA->AFR[1] |= 0x00000110; // set AF1 to PA9, PA10
GPIOA->MODER |= 0x00280000; // define GPIO modes to alternate function for PA9, PA10
USART1->BRR = 0x00000341; // set the baud rate, 9600 # 8MHz
USART1->CR1 = 0x0000002C; // enable te, re, and rx interrupt
USART1->CR1 |= 0x00000001; // enable ue
}
// initialize USART2
void USART2_Init(void)
{
RCC->APB1ENR |= 0x00020000; // enable USART2 clock
GPIOA->AFR[0] |= 0x00001100; // set AF1 to PA2, PA3
GPIOA->MODER |= 0x000000A0; // define GPIO modes to alternate function for PA2, PA3
USART2->BRR = 0x00000341; // set the baud rate, 9600 # 8MHz
USART2->CR1 = 0x0000000C; // enable te and re
USART2->CR1 |= 0x00000001; // enable ue
}
// handle the USART1 interrupt event
void USART1_IRQHandler(void)
{
char c;
while (1)
{
if (USART1->ISR & 0x00000020)
{
c = USART1->RDR;
}
else
{
break;
}
printf("%c", c);
}
}
// implement stdin/stdout/stderr functionality
struct __FILE{int handle;};
FILE __stdin = {0};
FILE __stdout = {1};
FILE __stderr = {2};
int fgetc(FILE *f)
{
int c;
c = USART2_Read();
if (c == '\r')
{
USART2_Write(c);
c = '\n';
}
USART2_Write(c);
return c;
}
int fputc(int c, FILE *f)
{
return USART2_Write(c);
}
I was able to get the ESP to respond to the AT commands with the following code. There are sections commented out as I was simply frankensteining my way to 'working' code. I was able to change the SSID and password via a hard coded string. I simply sent it by pressing 'Enter' to get the code to proceed.
As it turns out the issue laid in sending data to the ESP (rather than receiving, which was my initial theory). Now I need to get the code to receive an uint8_t[] from the terminal, but that is a separate issue from the original question so I'll mark this as answered.
Thank you #hamboy75, #Juraj, and #KamilCuk for your help!
#include "stm32f0xx.h"
#include <stdio.h>
#include <string.h>
void USART1_Init(void);
void USART2_Init(void);
void USART1_Write(char ch[]);
char USART1_Read(void);
void USART1_Get(unsigned char *string);
void USART1_PutChar(uint8_t ch);
void USART1_Write2(uint8_t *str);
int main(void)
{
// disable the interrupt detection
__disable_irq();
RCC->AHBENR |= 0x00020000; // enable port A clock
GPIOA->MODER |= 0x00000400; // set mode for PA5
USART1_Init();
USART2_Init();
char strCommand[50];
uint8_t str[] = "AT+CWSAP_CUR=\"tempNetwork\",\"tempPassword\",1,2,1,0\r\n";
NVIC_EnableIRQ(USART1_IRQn);
__enable_irq();
printf("\r\nInterface for ESP8266 AT commands.\r\n");
printf("Please enter the AT command: ");
gets(strCommand);
//USART1_Write(strCommand);
USART1_Write2(str);
printf("\r\n");
while (1);
}
// write data to the peripheral via USART1
void USART1_Write(char ch[])
{
// wait for the tx buffer to be empty
while (!(USART1->ISR & 0x00000080));
for (int i = 0; i < strlen(ch); i++)
{
//USART1->TDR = (ch[i] & 0xFF);
}
//USART1->TDR = '\r';
//USART1->TDR = '\n';
USART1->TDR = ('T' & 0xFF);
USART1->TDR = ('T' & 0xFF);
USART1->TDR = '\r';
USART1->TDR = '\n';
}
// write a string via USART1
void USART1_Write2(uint8_t *str)
{
while (*str != 0)
{
USART1_PutChar(*str);
str++;
}
}
// write one character via USART1
void USART1_PutChar(uint8_t ch)
{
while (!(USART1->ISR & 0x00000080));
USART1->TDR = ch;
}
// read data from the peripheral via USART1
char USART1_Read(void)
{
// wait while the rx buffer is empty
while (USART1->ISR & 0x00000020);
return USART1->RDR;
}
// write data to the PC via USART2
int USART2_Write(int ch)
{
// wait while the tx buffer is empty
while (!(USART2->ISR & 0x00000080));
USART2->TDR = (ch & 0xFF);
return ch;
}
// read data from the PC via USART2
int USART2_Read(void)
{
// wait while the rx buffer is empty
while (!(USART2->ISR & 0x00000020));
return USART2->RDR;
}
// initialize USART1
void USART1_Init(void)
{
RCC->APB2ENR |= 0x00004000; // enable USART1 clock
GPIOA->AFR[1] |= 0x00000110; // set AF1 to PA9, PA10
GPIOA->MODER |= 0x00280000; // define GPIO modes to alternate function for PA9, PA10
USART1->BRR = 0x00000341; // set the baud rate, 9600 # 8MHz
USART1->CR1 = 0x0000002C; // enable te, re, and rx interrupt
USART1->CR1 |= 0x00000001; // enable ue
}
// initialize USART2
void USART2_Init(void)
{
RCC->APB1ENR |= 0x00020000; // enable USART2 clock
GPIOA->AFR[0] |= 0x00001100; // set AF1 to PA2, PA3
GPIOA->MODER |= 0x000000A0; // define GPIO modes to alternate function for PA2, PA3
USART2->BRR = 0x00000341; // set the baud rate, 9600 # 8MHz
USART2->CR1 = 0x0000000C; // enable te and re
USART2->CR1 |= 0x00000001; // enable ue
}
// handle the USART1 interrupt event
void USART1_IRQHandler(void)
{
char c;
while (1)
{
if (USART1->ISR & 0x00000020)
{
c = USART1->RDR;
printf("%c", c);
}
else
{
break;
}
}
}
// implement stdin/stdout/stderr functionality
struct __FILE{int handle;};
FILE __stdin = {0};
FILE __stdout = {1};
FILE __stderr = {2};
int fgetc(FILE *f)
{
int c;
c = USART2_Read();
if (c == '\r')
{
USART2_Write(c);
c = '\n';
}
USART2_Write(c);
return c;
}
int fputc(int c, FILE *f)
{
return USART2_Write(c);
}

receiving and sending data from arduino to stml476RG

I am looking to receive serial data from an arduino, and then transmit the data received back to the arduino, however I am having trouble receiving the correct data. Below is my code, I am not sure on where I have gone wrong, can anyone see any problems?
I am using register level programming and using USART 3 on the STM32L476RG development board, an I am using ADM485 chip to transfer the data between each serial port.
#include "stm32L476XX.h"
#include "stdio.h"
int T ;
int R ;
uint8_t z;
void USART3_init(void)
{
USART3->BRR |= 26UL<<4; //BAUD RATE MANTISSA 234UL<<4
USART3->BRR |= 1UL<<0; // BAUD RATE FRACTION 6UL<<0
USART3->CR1 |= 1UL<<0; //enable USART
USART3->CR1 ^= 0UL<<28; //1 start bit, 8 data bits, n stop bit
USART3->CR1 ^= 0UL<<12; //also sets word length to 8 data bits
USART3->CR1 ^= 0UL<<10; //no parity control
USART3->CR1 |= 1UL<<6; //Transmission complete interrupt enabled
USART3->CR1 |= 1UL<<7; //TXE interrupt enable
USART3->CR1 |= 1UL<<5; //RXNEIE interrupt enable
USART3->CR2 ^=00UL<<12; //1 stop bit
USART3->CR1 |= 1UL<<3; // enable transmitter
USART3->CR1 |= 1UL<<2; // enable receiver
NVIC_EnableIRQ(USART3_IRQn); //enable USART interrupts
}
void Delay(void)
{
uint32_t i=0;
for (i=0; i<50000; i++){}
}
void USART3_IRQHandler(void)
{
//Delay();
if ((USART3->ISR>>5)&1UL) //Check if RXNE interrupt is high
{
z = USART3->RDR; //put what is on RDR into Z (also clears RXNE flag)
GPIOB->ODR |= 1UL<<5; //set transceiver into transmit mode USART3->TDR = z; // Clears TXIE flag and outputs z on TX
}
if ((USART3->ISR>>7)&1UL) //Check if TXIE interrupt is high
{
GPIOB->ODR &= 0UL<<5; //sets transceiver in receive mode
}
if ((USART3->ISR>>6)&1UL) //Check if TC interrupt is high
{
USART3->ICR |= 1UL<<6; //Clear TC flag
GPIOB->ODR &= 0UL<<5; //Set transceiver in receive mode
}
}
void RCC_GPIO_init(void)
{
RCC->APB1ENR1 |= 1UL<<18; //Enable USART 3 clock
RCC->AHB2ENR |= 1UL<<1; //Enable GPIOB clock
GPIOB->MODER = 0; //reset all register bits
GPIOB->MODER |= 2UL<<20; //enable GPIOB pin 10 as alternate function
GPIOB->MODER |= 2UL<<22; //enable GPIOB pin 11 as alternate function
GPIOB->MODER |= 1UL<<10; //enable GPIOB pin 5 as output
GPIOB->AFR[1] = 0; //reset all register bits
GPIOB->AFR[1] |= 7UL<<8; //enable GPIOB pin 10 as TX
GPIOB->AFR[1] |= 7UL<<12; //enable GPIOB pin 10 as RX
GPIOB->ODR ^= 0UL<<5; //GPIOB pin 5 as low (to put ADM485 transceiver in receive mode)
}
int main (void)
{
RCC_GPIO_init();
USART3_init();
while(1)
{
}
}

Using the Msp430fr5969 to send strings over Tx

I am trying to send data from the Msp430fr5969 Launchpad to the rn-52-ek so it can pass the data along through bluetooth.
#include <msp430.h>
void uartSend(unsigned char *pucData, unsigned char ucLength)
{
while(ucLength>0)
{
// Wait for TX buffer to be ready for new data
while(!(UCA1IFG & UCTXIFG));
// Push data to TX buffer
UCA1TXBUF = *pucData;
// Update variables
ucLength--;
pucData++;
}
}
void initUART()
{
/* Place UCA0 in Reset to be configured */
UCA0CTL1 = UCSWRST;
//Set BRCLK = SMCLK
UCA0CTL1 |= UCSSEL_2;
//Values found using table for 16Mhz and 115200 baudrate
UCA0BR0=8;
UCA0BR1=0;
UCA0MCTLW = 0xF7 << 8;
UCA0MCTLW |= 10 << 4;
UCA0MCTLW |= UCOS16;
//UCA0 out of reset
UCA0CTL1 &= ~UCSWRST;
}
int main(void) {
// disable watchdog timer
//------------------------
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
initUART();
unsigned char sendString[] = "Banana";
unsigned char length=6;
while(1)
{
uartSend(sendString,length);
}
return 0;
}
Nothing is happening when I run the above code, not even reading anything on the multimeter. What am I missing?
I know there are some bad practices, I just want to get it working and I'll add the interrupt based sending later.
You should set Port 2.5 as Tx for the UART

UART cannot RX GPS NMEA sentences

My UART is configured for 4800baud rate, Well I am not able to RX the NMEA sentences(GPS eval board) using the UART code pasted below. Individually GPS+Terminal and UART+Terminal is working fine . But GPS+UART , I am never able to RX any sentences
GPS default buad rate is 4800
Any idea where I am going wrong with UART???
/**
* uart default at 4800 ACLK= 32.768KHz
* #4800 bps
*/
void UART_default(void){
P3SEL = BIT3+BIT4;
UCA0CTL1 |= UCSWRST;
UCA0CTL1 |= UCSSEL_1;
UCA0BR0 = 0x06;
UCA0BR1 = 0x00;
UCA0MCTL |= UCBRS_6+UCBRF_0;
UCA0CTL1 &= ~UCSWRST;
UCA0IE |= UCRXIE;
}
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
volatile char byte;
switch(__even_in_range(UCA0IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2:
byte= UCA0RXBUF;
if (byte == '\r') {
push_char(byte); // At end of Data transmission
ptr = 0;
}
else{
push_char(byte);
ptr++;
}
break;
case 4:break;
default: break;
}
}
Did you try to replace the GPS by a PC with a USB <-> UART converter ?
This could validate the baudrate setup in your MSP430 as well as the ability to receive something.

Resources