微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > TI模拟硬件电路设计 > ADS1292R寄存器问题

ADS1292R寄存器问题

时间:10-02 整理:3721RD 点击:

我现在在用ADS1292R,用的内部晶振,单片机用的是f149,现在的问题是读出来的寄存器状态位是错的,下面是我的程序。


#include <msp430x14x.h>
char MST_Data = 0xAA,SLV_Data = 0xff;
unsigned char a[12];
unsigned char b[12];
#define SPI_ENABLE P2OUT &=~0x08;
#define SPI_DISABLE P2OUT |=0x08;
unsigned char regdata[11]={0x02,0xeb,0x18,0x00,0x00,0x30,0x0f,0x40,0x02,0x01,0x03};//二通道心电测试信号,无呼吸
void Stop_Read_Data_Continuous (void)
{
unsigned int i=0;
SPI_ENABLE; // /CS enable
//for(i=0;i<10;i++);
//while (!(IFG1&URXIFG0)); // Clear flag
TXBUF1 =0x11; // Send SDATAC
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
// UCA0IFG &= ~(UCRXIFG+UCTXIFG); // Clear flag 可能自动复位(zhao)
SPI_DISABLE; // /CS disable
for(i=0;i<10;i++);
}

void Start_Read_Data_Continuous (void)
{
unsigned int i=0;
SPI_ENABLE;
// while (!(IFG1&URXIFG0)); // Clear flag
TXBUF1 =0x10; // Send RDATAC
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
// UCA0IFG &= ~(UCRXIFG+UCTXIFG); // Clear flag
// UCA0IFG &= ~UCRXIFG; // Clear flag
SPI_DISABLE;
for(i=0;i<10;i++);
}

void SPI_RegRead(unsigned char addr, unsigned char *buffer, unsigned char count)
{
unsigned int i=0,j=0;

//P1OUT |=BIT1;
//退出连续读数模式
Stop_Read_Data_Continuous (); //When in RDATAC mode, the RREG command is ignored.Send SDATAC MUST BE SENT
//for(i=0;i<50;i++);

SPI_ENABLE; // /CS enable

TXBUF1 =addr+0x20; // Send address

while ((IFG2 & UTXIFG1) == 0); // USART0 TX buffer ready?
// UCA0IFG &= ~(IFG+UCTXIFG); // Clear flag

TXBUF1 = count-1; // regedit count ge shu
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
// UCA0IFG &= ~(UCRXIFG+UCTXIFG); // Clear flag

for (i = 0; i<count;i++)
{
TXBUF1 = 0x55; //Initiate next data RX, meanwhile..
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
buffer[i] = RXBUF1; // Store data from last data RX
TXBUF0=RXBUF1;
while (!(IFG2&URXIFG1)); // Wait for TXBUF ready
for(j=0;j<10;j++);
P2OUT =~0X04;

}

SPI_DISABLE; // /CS disable
//P1OUT = 0x00;
for(i=0;i<10;i++);
//回到连续模式方便读数
Start_Read_Data_Continuous ();
for(i=0;i<10;i++);

}
void SPI_Regwrite(unsigned char addr,unsigned char *data,unsigned char count)
{
unsigned int i=0,j=0;
//P1OUT |=BIT1;
//退出连续读数模式
Stop_Read_Data_Continuous ();

SPI_ENABLE; // /CS enable

//UCA0IFG &= ~(UCRXIFG+UCTXIFG); // Clear flag
TXBUF1 =addr+0x40; //发送地址信息; 首地址是0x01;(zhao)
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready

// UCA0IFG &= ~(UCRXIFG+UCTXIFG); // Clear flag
TXBUF1 =count-1; //发送header; //发送的寄存器数量为10个(zhao)
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
for (i = 0; i<count;i++)
{

//UCA0IFG &= ~(UCRXIFG+UCTXIFG); // Clear flag
TXBUF1 =data[i];

while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
for(j=0;j<30;j++);


}

SPI_DISABLE; // /CS disable

//回到连续模式方便读数
Start_Read_Data_Continuous ();

}

void intSPI1()
{
P5SEL |= 0x0E; // P5.1,2,3 SPI option select
P5OUT &= ~0x01;
P5DIR |= 0x01;
U1CTL = CHAR + SYNC + MM + SWRST; // 8-bit, SPI, Master
U1TCTL = CKPL + SSEL1 + STC; // Polarity, SMCLK, 3-wire
U1BR0 = 0x00; // SPICLK = SMCLK/2
U1BR1 = 0x03;
U1MCTL = 0x00;
ME2 |= USPIE1; // Module enable
U1CTL &= ~SWRST; // SPI enable

IE2 |= URXIE1 ; // RX and TX interrupt enable
}

void intUART0()
{
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x03; // 32k/9600 - 3.41
UBR10 = 0x00; //
UMCTL0 = 0x4A; // Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
}

void Delay_ms(unsigned int n)
{
unsigned int l,m;
for(l=0;l<n;l++)
for(m=0;m<1000;m++);
}
void main( void )
{

WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
P1OUT = 0x000;
P1DIR |= 0x001; //设置P1.0为输出
P1SEL = 0x010;
P2DIR |= 0x00f; //0,1,2,3输出
P2OUT |=0x01; //START,RST高电平

P5SEL = 0x020; //设置P3端口为SPI模式

intSPI1();
intUART0();
Delay_ms(5);




//SPI_RegRead(0x00,a,12); //读取初始寄存器,检验电路连接是否正确
SPI_Regwrite(0x01,regdata,11); //写入配置寄存器,
Delay_ms(5);
SPI_RegRead(0x00,b,12); // 再次读出寄存器 检验是否写入正确
Delay_ms(5);
P2OUT |=0x02; //START,RST高电平
SPI_ENABLE;
_EINT();

// TXBUF0 = MST_Data; //传输第一个字符
while(1)
{
};
//LPM0; //关CPU,进入低功耗模式

}
#pragma vector=USART1RX_VECTOR
__interrupt void SPI1_rx (void)
{
unsigned char j=0;
// unsigned char j=0;

for(j=0;j<9;j++)
{
// while((UCA0IFG&UCTXIFG)==0);
TXBUF1 = 0x55;
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready

//TXBUF0 = RXBUF1;
// buffer[i]= UCA0RXBUF;
}


}

#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
// RXBUF0 to TXBUF0
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)
}

 SPI 时序和信号脉冲没有弄对的话, 很容易错误的, 不知道怎么个错误情况?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top