[英]SPI connection with MSP430F2013(Master) to Arduino uno(SLAVE)
I working on a project where i need measurement of a bridge circuit(strain gauge) through MCU.我正在做一个项目,我需要通过 MCU 测量电桥电路(应变计)。 For that I am using a MSP430F2013 MCu with 16 bit ADC.
为此,我使用的是带有 16 位 ADC 的 MSP430F2013 MCu。 I dont have data logging hardware for this Mcu so I am trying to connect it with Arduino Uno for recording measurements.
我没有此 MCU 的数据记录硬件,因此我尝试将其与 Arduino Uno 连接以记录测量结果。 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.
我不擅长编程,所以到目前为止,我已经拼凑代码来配置 MSP430 的 ADC,我看到它通过在 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).
我曾尝试在 MSP430 和 Arduino 中设置 SPI,但不知道哪里出了问题(这是对我的问题的直截了当的解释:即使我听起来有点无知/愚蠢)。 It will be of great help if someone can point out mistakes here.
如果有人可以在这里指出错误,那将有很大帮助。
Here is a code of both MCU这是两个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.我得到了 ADC 的结果,但没有进一步的结果(我不知道如何测试 usi。
As you are using launchpad, don't bother with arduino.当您使用启动板时,不要打扰 arduino。 Launchpad also provides USB-UART.
Launchpad 还提供 USB-UART。
see https://www.embeddedrelated.com/showarticle/420.php见https://www.embeddedrelated.com/showarticle/420.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.