ADS1292连续发送
我现在可以正常的读写寄存器,但是连续配置连续发送模式的时候,每次发回一个数据DRDY就拉低,因此只能发回C0,C0,C0,
#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[7]={0x02,0Xab,0x10,0x05,0x05,0x00,0x00};//二通道心电测试信号,无呼吸0x02,0xeb,0x18,0x00,0x00,0x30,0x0f,0x40,0x02,0x01,0x03fCLK = 512 kHz
unsigned char regdata1[3]={0x02,0x02,0x01};
unsigned char regdata2[11]={0x00};
void Delay_ms(unsigned int n)
{
unsigned int l,m;
for(l=0;l<n;l++)
for(m=0;m<1000;m++);
}
void Stop_Read_Data_Continuous (void)
{
unsigned int i=0;
SPI_ENABLE; // /CS enable
for(i=0;i<10;i++);
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 =0x11; // Send SDATAC
SPI_DISABLE; // /CS disable
for(i=0;i<10;i++);
}
void Start_Read_Data_Continuous (void)
{
unsigned int i=0;
SPI_ENABLE;
for(i=0;i<10;i++);
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 =0x10; // Send RDATAC
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;
Stop_Read_Data_Continuous (); //When in RDATAC mode, the RREG command is ignored.Send SDATAC MUST BE SENT
for(i=0;i<10;i++);
SPI_ENABLE; // /CS enable
for(j=0;j<10;j++);
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 =addr|0x20; // Send address
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 = 0x00|(count-1); // regedit count
for (i = 0; i<count;i++)
{
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 = 0x00; //Initiate next data RX, meanwhile..
Delay_ms(20);
while (!(IFG2&URXIFG1)); // Wait for TXBUF ready
buffer[i] = RXBUF1; // Store data from last data RX
TXBUF0= buffer[i];
for(j=0;j<10;j++);
}
SPI_DISABLE; // /CS disable
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;
Stop_Read_Data_Continuous ();
SPI_ENABLE; // /CS enable
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 =addr+0x40; //发送地址信息; 首地址是0x01;(zhao)
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 =count-1; //发送header; //发送的寄存器数量为10个(zhao)
for(j=0;j<500;j++);
for(j=0;j<500;j++);
for (i = 0; i<count;i++)
{
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 =data[i];
for(j=0;j<500;j++);
}
SPI_DISABLE; // /CS disable
//Start_Read_Data_Continuous ();
}
void intSPI1()
{
int i;
P5SEL |= 0x0E; // P5.1,2,3 SPI option select
P5OUT &= ~0x01;
P5DIR |= 0x01;
BCSCTL1 &= ~XT2OFF; // XT2on
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)
U1CTL = CHAR + SYNC + MM + SWRST; // 8-bit, SPI, Master
U1TCTL = SSEL1 + STC; // Polarity, SMCLK, 3-wire
U1BR0 = 0xa0; // SPICLK = SMCLK/2
U1BR1 = 0x00;
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 main( void )
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
P1OUT = 0x00;
P1IES |= 0x00; //上升沿触发
P1IFG = 0x00; //中断标志位清零
P1IE |=0xff; //P1模块中断允许
P2DIR |= 0x00f; //0,1,2,3输出
P2OUT |=0x01; //START,RST高电平
// P2OUT |=0x02; //START,RST高电平
P5SEL = 0x020; //设置P3端口为SPI模式
intSPI1();
intUART0();
Delay_ms(5);
//SPI_RegRead(0x00,a,12); //读取初始寄存器,检验电路连接是否正确
SPI_Regwrite(0x08,regdata1,3); //写入配置寄存器,
Delay_ms(5);
SPI_Regwrite(0x0b,regdata2,1); //写入配置寄存器,
Delay_ms(5);
Delay_ms(5);
SPI_Regwrite(0x01,regdata,7); //写入配置寄存器,
Delay_ms(5);
SPI_RegRead(0x00,b,12); // 再次读出寄存器 检验是否写入正确
Delay_ms(5);
P2OUT |=0x02;
Delay_ms(50);
SPI_ENABLE;
Delay_ms(50);
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 =0x10; // Send RDATAC
Delay_ms(100);
SPI_DISABLE; // /CS disable
Delay_ms(100);
Delay_ms(100);
Delay_ms(100);
Delay_ms(100);
Delay_ms(100);
Delay_ms(100);
Delay_ms(100);
Delay_ms(100);
_EINT();
SPI_ENABLE;
while(1)
{
};
//LPM0; //关CPU,进入低功耗模式
}
#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)
}
#pragma vector = PORT1_VECTOR //P1中断服务子程序
__interrupt void P1_Interrupt(void)
{
unsigned char i=0;
if(P1IFG==0x01)
{
P1IFG=0; //清除标志位
for(i=0;i<9;i++)
{
while (!(IFG2&UTXIFG1)); // Wait for TXBUF ready
TXBUF1 = 0x00; //Initiate next data RX, meanwhile..
Delay_ms(2);
while (!(IFG2&URXIFG1)); // Wait for TXBUF ready
TXBUF0 = RXBUF1;
Delay_ms(2);
}
}
else
P1IFG=0; //清除标志位
}
DRDY 是告诉主机, 有数据需要读取, 这是发时钟就能收到数据.
我知道DRDY的作用,现在问题是发送中断不对,每次发挥一个数据,DRDY就拉低,你有没有程序可以参考一下,谢谢!
楼主,你现在可以正常接收数据了吗