Akiyer 发表于 2011-3-15 15:01:24

M16驱动两片MAX531遇到发送后一字节时进入死循环

用M16硬件SPI驱动两片MAX531,发送高字节时正常,再发低字节时进入死循环,附发送程序:
void DAC1_Conver(unsigned int senddata)
{
    unsigned char temphi,templo;                  
    temphi = (senddata>>8)&0xff;               //发送字节高8位(12bit);
    templo = senddata&0xff;                    //发送字节低8位(12bit);
    SBI(DDRD,4);
    CBI(PORTD,4);            

    SPDR   = temphi;   
    while(!(SPSR&(1<<SPIF)));               //等待转换完成   
    SPDR   = templo;
    while(!(SPSR&(1<<SPIF)));                //等待转换完成   程序死在这里

   SBI(PORTD,4);
   
}
更离奇的是把电源拨掉再插上去就时可以,如果按复位键就肯定在发送完templo,检测SPIF时一定卡死在这;

clarepeng 发表于 2011-8-21 13:59:56

回复【楼主位】Akiyer
-----------------------------------------------------------------------

初学的,没看懂......呵呵!

ouravr2012 发表于 2012-3-30 09:37:35

正在学习这个MAX531驱动,楼主能把单个驱动成功的程序贡献出来吗?{:biggrin:}

RUANJI 发表于 2012-4-7 11:26:05

楼主试试用个函数封装下void SPI_SendByte( unsigned char byte )
{
    unsigned char DummyRead;
    SPDR = byte;
    while(!(SPSR&(1<<SPIF)));
    DummyRead = SPDR;
}
页: [1]
查看完整版本: M16驱动两片MAX531遇到发送后一字节时进入死循环