SPI与MSP430F2013(主)连接到Arduino Uno(从属)
我从事一个项目,需要通过MCU测量桥梁电路(应变仪)。为此,我使用的是16位ADC的MSP430F2013 MCU。我没有此MCU的数据记录硬件,因此我试图将其与Arduino Uno连接起来以进行录制测量。我不擅长编程任何内容,因此到目前为止,我已经将代码拼凑在一起,以配置MSP430的ADC,我看到的是通过在Code Composer Studio中应用断点来工作。我试图在MSP430和Arduino中设置SPI,但不知道问题出在哪里(这是我问题的钝性外观:即使我听起来有些无知/愚蠢)。如果有人可以在这里指出错误,这将有很大的帮助。
这是两个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
}
}
我得到了ADC的结果,但没有任何进一步的代码(我不知道如何测试USI。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用启动板时,不必担心 arduino。 Launchpad 还提供 USB-UART。
请参阅https://www.embeddedlinked.com/showarticle/420.php
As you are using launchpad, don't bother with arduino. Launchpad also provides USB-UART.
see https://www.embeddedrelated.com/showarticle/420.php