0

I working on a project where i need measurement of a bridge circuit(strain gauge) through MCU. For that I am using a MSP430F2013 MCu with 16 bit ADC. I dont have data logging hardware for this Mcu so I am trying to connect it with Arduino Uno for recording measurements. I am not good at programming anything so till now I have pieced together code to configure ADC of MSP430 which I see is working by applying breakpoint in Code Composer studio. I have tried to set up SPI in both MSP430 and Arduino but dont know where things are going wrong( this is a blunt explantion of my problem: even if i sound a bit ignorant/stupid). It will be of great help if someone can point out mistakes here.

Here is a code of both MCU

#include <msp430.h>
    volatile unsigned int i;
    volatile unsigned int s;
int main(void)
{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer

  BCSCTL1 = CALBC1_16MHZ;
  DCOCTL=CALDCO_16MHZ;

  //SMCLK on Pin6 (P1.4) - just for service and testing
  P1DIR |= 0x10;   //P1.4 as output
  P1SEL = 0x10;    //SMCLK to P1.4

  //I/O-Pin preparation
  P1DIR |= BIT0; //set P1.0 to output direction - for using the LED on Pin2
  P1DIR |= BIT7; //set P1.7 to output direction - as signal for data are ready to use

  //SPI settings

  USICTL0 &= ~USISWRST; //USI released for operation
  USICTL1 &= ~USII2C; //switch USI to SPI-Mode
  USICTL0 |= USIMST; //set to SPI-Master-Mode

  USICKCTL = USIDIV_3+USISSEL_2+USICKPL;
  USICTL0 |= USIPE6 + USIPE5; //SDO-Port enabled; Pin8
  USICTL0 |= USIPE7; //SDI-Port disabled; Pin9 can be used for normal in/out
  USICTL0 |= USIOE; //activate output (data goes from MSP to Warrior56)
  USICNT |= USI16B; //init load counter for 16-bit-data
  //inactive state is low
  //data is changed on the first SCLK edge and captured on the following edge

  P1DIR |= 0x01;                            // Set P1.0 to output direction
  SD16CTL = SD16REFON + SD16SSEL_1;         // 1.2V ref, SMCLK
  SD16INCTL0 = SD16INCH_1;                  // A1+/-
  SD16CCTL0 =  SD16UNI + SD16IE;            // 256OSR, unipolar, interrupt enable
  SD16AE = SD16AE1;                         // P1.1 A1+, A1- = VSS
  SD16CCTL0 |= SD16SC;                      // Set bit to start conversion



    while(1)
    {
    SD16CCTL0 |= SD16SC;
 s = SD16MEM0;
 
    for (i = 0xFFFF; i > 0; i--);           // Delay
    USICTL1 |= USIIFG;                 // Set flag and start communication
    USISR = s;

    if (USISRL = s)
      P1OUT |= 0x01;
    else
      P1OUT &= ~0x01;
    __bis_SR_register(LPM0_bits + GIE);

    }
}
#pragma vector = SD16_VECTOR; // Interrupt service routine for
__interrupt void SD16ISR(void) // conversion
{

    s = SD16MEM0;

}


//////////////////////////////////////////////////
Here is arduino code  as slave
#include <SPI.h>
char buff [50];
volatile byte indx;
volatile boolean process;

void setup (void) {
   Serial.begin (115200);
   pinMode(MOSI, INPUT); // have to send on master in so it set as output
   SPCR |= _BV(SPE); // turn on SPI in slave mode
   indx = 0; // buffer empty
   process = false;
   SPI.attachInterrupt(); // turn on interrupt
}

ISR (SPI_STC_vect) // SPI interrupt routine 
{ 
   byte c = SPDR; // read byte from SPI Data Register
   if (indx < sizeof buff) {
      buff [indx++] = c; // save data in the next index in the array buff
      if (c == '\r') //check for the end of the word
      process = true;
   }
}

void loop (void) {
   if (process) {
      process = false; //reset the process
      Serial.println (buff); //print the array on serial monitor
      indx= 0; //reset button to zero
   }
}

I have got result of ADC but not anything further( i dont know how to test usi.

2
  • Dir you forgot to put SPI out of "software reset"? I mean something like USICTL0 |= USISWRST; Commented Apr 13, 2022 at 11:06
  • Ok, I did it now. But still nothing. One more thing, I could not find Arduino Slave code to change clock phase and polarity; I know about this but implementing them didn't changed a tthing in result SPI.setDataMode (SPI_MODE0); SPI.setDataMode (SPI_MODE1); SPI.setDataMode (SPI_MODE2); SPI.setDataMode (SPI_MODE3); Commented Apr 19, 2022 at 18:56

1 Answer 1

0

As you are using launchpad, don't bother with arduino. Launchpad also provides USB-UART.

see https://www.embeddedrelated.com/showarticle/420.php

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.