打印

LPC2368 用SPI0(P1.20 等端口)问题。

[复制链接]
2400|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hehu8|  楼主 | 2010-4-7 19:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 hehu8 于 2010-4-9 20:26 编辑

LPC2368上有两组SSP0端口,我用P0.15等那一组可以通信。但我用LPC2368的另一组SSP0端口(p1.20等端口),测试SCK0等信号线没有波形。源程序如下:


BYTE SPIbuf[]="1234" ;

int main (void)
{
    SPIInit();
    while (1)
    {   
        SPISend(SPIbuf,4);
    }

   return 0;
}

DWORD SPIInit( void )
{
  TxCounter = 0;
  PCONP |= (1 << 21); /* by default, it's enabled already, for safety reason */
  S0SPCR = 0x00;
  /* Port 0.15 SPI SCK, port0.16 uses GPIO SPI_SEL,
  port0.17 MISO, port0.18 MOSI */
  //PINSEL0 |= 0xC0000000;
  //PINSEL1 |= 0x0000003C;
  //IODIR0 = SPI0_SEL;
  //IOSET0 = SPI0_SEL;

   PINSEL3 &= 0x0003C300;   //对P1.20-P1.28进行端口配置。 0x0003CF00
   IODIR1 = SSP0_SEL;
  IOSET1 = 0x02000000;   //25-ssel 置高

  /* Setting SPI0 clock, for Atmel SEEPROM, SPI clock should be no more
  than 3Mhz on 4.5V~5.5V, no more than 2.1Mhz on 2.7V~5.5V */
  S0SPCCR = 2;    //48m/2=24M/12=2Mhz
#if INTERRUPT_MODE
  if ( install_irq( SPI0_INT, (void *)SPI0Handler, HIGHEST_PRIORITY ) == FALSE )
  {
return (FALSE);
  }
  /* 8 bit, CPOL=0,CPHA=0, master mode, MSB first, interrupt enabled */
  S0SPCR = SPI0_SPIE | SPI0_MSTR  ;
#else
  S0SPCR = SPI0_MSTR ;    //没有允许SPI???
#endif
  return( TRUE );
}


void SPISend( BYTE *buf, DWORD Length )
{
  DWORD i;
  BYTE Dummy;
  Dummy = Dummy;
  if ( Length == 0 )
return;
  for ( i = 0; i < Length; i++ )
  {
S0SPDR = *buf;
#if INTERRUPT_MODE
/* In the interrupt, there is nothing to be done if TX_DONE, SPI transfer
complete bit, is not set, so it's polling if the flag is set or not which
is being handled inside the ISR. Not an ideal example but show how the
interrupt is being set and handled. */
while ( (SPI0Status & SPI0_TX_DONE) != SPI0_TX_DONE );
SPI0Status &= ~SPI0_TX_DONE;
#else
while ( !(S0SPSR & SPIF) );
#endif
Dummy = S0SPDR;  /* Flush the RxFIFO */
buf++;
  }
  return;
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

124

主题

179

帖子

0

粉丝