Hello respective members,
I need an advice for managing uart data so here is what i think i am doing :
So my question is how do i manage data the data coming in matlab contains 1 byte out of 4 byte from one channel and and then this is repeated for other two channels as well.
here is code for transmission of ADC data from MCU
I need an advice for managing uart data so here is what i think i am doing :
- I have 4 channel ADC out of which I use 3 channels.
- I take one sample(24bit) from each channel sequestially via SPI with MCU MSP430f5529.
- I transmit byte by byte to serial port in terminal or matlab.
So my question is how do i manage data the data coming in matlab contains 1 byte out of 4 byte from one channel and and then this is repeated for other two channels as well.
here is code for transmission of ADC data from MCU
Code:
// MSP430F552x
// -----------------
// /|\ | |
// | | |
// Master---+->|RST |
// | |
// | P3.0|-> Data Out (UCB0SIMO)
// | |
// | P3.1|<- Data In (UCB0SOMI)
// | |
// | P3.2|-> Serial Clock Out (UCB0CLK)
//
//
//******************************************************************************
#include <msp430.h>
#include "ADS1220.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
unsigned int j = 0x00;
unsigned int i;
unsigned int k;
volatile long adc_value1;
volatile long adc_value2;
volatile long adc_value3;
unsigned char temp;
char string[32];
float adcvalue;
float voltage;
int channel;
/*variable to store single smaple read from adc*/
static void putDataToUart(uint8_t byte);
static void putDataToUart(uint8_t byte){
UCA0TXBUF = byte;
while(!UCBUSY);
// __delay_cycles(5000);
}
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
// P2DIR &= ~BIT6; //DRDY_ pin
//******************SPI****************************//
P3SEL |= BIT0+BIT1+BIT2; // P3.3,4 option select
UCB0CTL1 |= UCSWRST; // **Put state machine in reset**
UCB0CTL0 |= UCSYNC+UCMSB+UCMST; // 3-pin, 8-bit SPI Master, MSB
UCB0CTL1 |= UCSSEL_2; // SMCLK 16Mhz
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
//***************UART********************//
P3SEL |= BIT3+BIT4; // P3.3,4 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 9; // 1MHz 115200 (see User's Guide)
UCA0BR1 = 0; // 1MHz 115200
UCA0MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
//*************************ADS1220*******************************//
ADS1220Init();
ADS1220Config();
ADS1220SendStartCommand();
channel |= 0;
volatile uint8_t tmp = 0;
__delay_cycles(1000);
int channels[3] = {ADS1220_MUX_0_G, ADS1220_MUX_1_G, ADS1220_MUX_2_G};
int crChannel = 0;
while(1)
{
if(crChannel == 0)
{
UCA0TXBUF = '/';
while(!UCBUSY);
}
ADS1220SetChannel(channels[crChannel]);
ADS1220SendStartCommand();
__delay_cycles(1000);
while(0 != P2IN & BIT6);
adc_value1 = ADS1220ReadData();
uint8_t tmp = ((adc_value1 >> 24) & 0xff);
/*put the first byte to Uart*/
putDataToUart(tmp);
/*prepare the third byte data*/
tmp = ((adc_value1 >> 16) & 0xff);
/*put the first byte to Uart*/
putDataToUart(tmp);
/*prepare the second byte data*/
tmp = ((adc_value1 >> 8) & 0xff);
/*put the first byte to Uart*/
putDataToUart(tmp);
/*prepare the first byte data*/
tmp = (uint8_t )(adc_value1 & 0x000000FF);
/*put the first byte to Uart*/
putDataToUart(tmp);
crChannel += 1;
crChannel %= 3;
}
}