Part Number: MSP430F5132
Other Parts Discussed in Thread: ISO3088, , MSP430F5529
Tool/software: Code Composer Studio
Hello,
I am working on an RS485 device which is controlled by MSP430F5132IDA. Here is the comments about my custom device:
- MSP430F5132 is the MCU on the board and it has I/Os and RS485 communication using ISO3088 TI device.
- If I dont use any UART, everything is working fine.
- If the mcu transmits to PC, everything is working fine.
- If the mcu receives a command (Like "360751SETO1#") and answer back the string "ACK360751?", it fails after transmitting 88th string (I dont know why it is 88, I put some disable interrupt, clear interrupt and enable interrup codes it increased to195th). MCU totally stops, no status led blinking. It stuck at delay(20000))
Here is the screen print at pc side:
Here is the simple MSP430F5132 code (from MSP430F5529 example) for UART communication:
#include "driverlib.h"
#define STATUS1 GPIO_PIN6
#define STATUS2 GPIO_PIN5
#define IN1 GPIO_PIN4
#define IN2 GPIO_PIN5
#define IN3 GPIO_PIN6
#define IN4 GPIO_PIN7
#define IN5 GPIO_PIN0
#define IN6 GPIO_PIN1
#define IN7 GPIO_PIN2
#define IN8 GPIO_PIN3
#define OUT1 GPIO_PIN1
#define OUT2 GPIO_PIN0
#define OUT3 GPIO_PIN7
#define OUT4 GPIO_PIN6
#define OUT5 GPIO_PIN5
uint8_t durum = 0x00;
uint8_t check = 0, sendACK=0, donguKontrol = 0;
uint8_t sendMessage = 1, receiveEnable = 0, charReceived = 0;
char charArray[12],charArrayCopy[12];
volatile int i,c=0;
uint8_t receivedData = 0x00;
void main(void)
{
//Stop WDT
WDT_A_hold(WDT_A_BASE);
//outs low first, prevent flickering at outputs
GPIO_setOutputHighOnPin(GPIO_PORT_P2, OUT5 + OUT4 + OUT3);
GPIO_setOutputHighOnPin(GPIO_PORT_P3, OUT2 + OUT1 + STATUS2 + STATUS1);
//outputs
GPIO_setAsOutputPin(GPIO_PORT_P2, OUT5 + OUT4 + OUT3);
GPIO_setAsOutputPin(GPIO_PORT_P3, OUT2 + OUT1 + STATUS2 + STATUS1);
GPIO_setOutputHighOnPin(GPIO_PORT_P2, OUT5 + OUT4 + OUT3);
GPIO_setOutputHighOnPin(GPIO_PORT_P3, OUT2 + OUT1);
GPIO_setOutputLowOnPin(GPIO_PORT_P3, STATUS2 + STATUS1);
//inputs
GPIO_setAsInputPin(GPIO_PORT_P1,IN1 + IN2 + IN3 + IN4);
GPIO_setAsInputPin(GPIO_PORT_P2,IN5 + IN6);
//rs485 de re
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN3);
//uart - rs485
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN1 + GPIO_PIN2);
//Baudrate = 9600, clock freq = 1.048MHz
//UCBRx = 109, UCBRFx = 0, UCBRSx = 2, UCOS16 = 0 --> Copied from MSP430F5529 example
USCI_A_UART_initParam param = {0};
param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
param.clockPrescalar = 109;
param.firstModReg = 0;
param.secondModReg = 2;
param.parity = USCI_A_UART_NO_PARITY;
param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
param.uartMode = USCI_A_UART_MODE;
param.overSampling = USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
if(STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, ¶m))
{
return;
}
//Enable UART module for operation
USCI_A_UART_enable(USCI_A0_BASE);
//Enable Receive Interrupt
USCI_A_UART_clearInterrupt(USCI_A0_BASE,USCI_A_UART_RECEIVE_INTERRUPT);
USCI_A_UART_enableInterrupt(USCI_A0_BASE,USCI_A_UART_RECEIVE_INTERRUPT);
__enable_interrupt();
while(1)
{
if(charReceived == 1){
GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN3);
_delay_cycles(8000);
USCI_A_UART_transmitData(USCI_A0_BASE, 'A');
USCI_A_UART_transmitData(USCI_A0_BASE, 'C');
USCI_A_UART_transmitData(USCI_A0_BASE, 'K');
USCI_A_UART_transmitData(USCI_A0_BASE, '3');
USCI_A_UART_transmitData(USCI_A0_BASE, '6');
USCI_A_UART_transmitData(USCI_A0_BASE, '0');
USCI_A_UART_transmitData(USCI_A0_BASE, '7');
USCI_A_UART_transmitData(USCI_A0_BASE, '5');
USCI_A_UART_transmitData(USCI_A0_BASE, '1');
USCI_A_UART_transmitData(USCI_A0_BASE, '?');
_delay_cycles(8000);
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN3);
charReceived = 0;
}
GPIO_setOutputHighOnPin(GPIO_PORT_P3,STATUS1);
_delay_cycles(20000);
GPIO_setOutputLowOnPin(GPIO_PORT_P3,STATUS1);
_delay_cycles(20000);
}
}
//******************************************************************************
//
//This is the USCI_A0 interrupt vector service routine.
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A0_VECTOR)))
#endif
void USCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,4))
{
//Vector 2 - RXIFG
case 2:
receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
if(receivedData != '#') // Check value
{
charArray[c] = receivedData;
c++;
charReceived = 0;
}else{
charReceived = 1;
}
break;
default: break;
}
}
Looking forward for your advices.
Best regards,
Onur
