用的P5的SPI,程序如下,按照LDC1000使用说明自己写的,是不是我理解错了,读出来的要么就是FF要么就是00,为什么,哪错了
#include<msp430x14x.h>
#define SPI_SEL P5SEL
#define SPI_DIR P5DIR
#define SPI_IN P5IN
#define SPI_OUT P5OUT
#define CSn BIT0
#define SIMO BIT1
#define SOMI BIT2
#define UCLK BIT3
#define uchar unsigned char
#define ulong unsigned long
#define uint unsigned int
void init_spi(void)//msp430 spi初始化 同步串行接口
{
SPI_DIR |= CSn;
SPI_OUT |= CSn;
U1CTL |= SWRST; // 芯片复位
U1CTL |= CHAR + SYNC + MM; // 8-bit SPI 主机模式
U1TCTL |= CKPH + SSEL1 + SSEL0 + STC; // SMCLK,3线模式
U1BR0 = 0x06;
U1BR1 = 0x00;
U1MCTL = 0x00;
ME2 |= USPIE1; // 使能SPI #define USPIE1 (0x10)
UCTL1 &= ~SWRST; // 取消复位
SPI_SEL |= SIMO + SOMI + UCLK;//引脚功能选择,第二功能
SPI_DIR |= SIMO + UCLK; // 端口方向设置
}
void LDC1000_WriteData(char addr,char value)
{
SPI_OUT &= ~CSn; // 使能端低电平
while (SPI_IN & SOMI);
while (!(IFG2 & UTXIFG1));
U1TXBUF = addr & ~0x80;
while (!(IFG2 & UTXIFG1));
U1TXBUF = value;
SPI_OUT |= CSn; // 使能端高电平
}
char LDC1000_ReadData(char addr)
{
char x;
SPI_OUT &= ~CSn;
while (SPI_IN & SOMI);
while (!(IFG2 & UTXIFG1));
U1TXBUF = (addr | 0x80);
while (!(IFG2 & URXIFG1));
x = U1RXBUF;
while (!(IFG2 & UTXIFG1));
SPI_OUT |= CSn; // 使能端高电平
return x;
}
void Init_LDC1000_R(void)
{
init_spi();
LDC1000_WriteData(0x01, 0x13);
LDC1000_WriteData(0x02, 0x3A);
LDC1000_WriteData(0x03, 0X94);
LDC1000_WriteData(0x04, 0x17);
LDC1000_WriteData(0x05, 0x03);
LDC1000_WriteData(0x06, 0x50);
LDC1000_WriteData(0x07, 0x14);
LDC1000_WriteData(0x08, 0xC0);
LDC1000_WriteData(0x09, 0x12);
LDC1000_WriteData(0x0A, 0x02);
LDC1000_WriteData(0x0B, 0x01);
}
此帖出自
小平头技术问答
换了个方法解决了,不用它的硬件spi,用程序去模拟它的功能,反倒比较好用,另外也可能是2个接地脚用了同一个,导致输出不对
一周热门 更多>