roboforum.ruТехнический форум по робототехнике. |
|
|
void init_spi(void)
{
PCONP |= (1 << 8); //Power ON
/* Configure Pin Connect Block */
PINSEL1|=0x0000003C; //MOSI & MISO
PINSEL0|=0xC0000000; //SCK
/* Set to highest speed for SPI at 10 MHz- > 1.25 MHz */
//S0SPCCR=0x8;
/* Device selected as master */
//SPI Mode 3:
//CPOL=1
//CPHA=1
//MASTER mode
//MSB first
S0SPCCR= 32; //SPI clk = PCLK_SPI/S0SPCCR
S0SPCR = 0x0838; //830
}
char spi(char data)
{ char data_in;
/* Write data out */
S0SPDR=data;
/* Wait for transfer to be completed */
while ( !(S0SPSR & SPIF) );
data_in=S0SPDR;
return data_in;
}
void SPI0Handler (void) __irq
{
DWORD regValue;
unsigned int data_spi;
if (S0SPSR); // (dummy) read status register
data_spi = S0SPDR; // read data received
S0SPDR = spi_counter; // next data to transmit
S0SPINT = 0x01; // reset interrupt flag
VICVectAddr = 0; // reset VIC
SPIdata=data_spi;
SPIflag=1;
spi_counter++;
}
void init_SPI( void )
{
PCONP |= (1 << 8); //SPI0 Power ON
//S0SPCR = 0x00;
PINSEL0|=(1U<<30)|(1U<<31); //SCK
PINSEL1|=(1U<<0 )|(1U<<1 ); //SSEL
PINSEL1|=(1U<<2 )|(1U<<3 ); //MISO
PINSEL1|=(1U<<4 )|(1U<<5 ); //MOSI
S0SPCCR = 0x8; //Clock select - max clock speed = PLCK/8
S0SPCR = 0x089C; // 8 bit, CPHA=1, CPOL=1, slave mode, LSB first, interrupt enabled
//0898
if ( install_irq( SPI0_INT, (void *)SPI0Handler, HIGHEST_PRIORITY) == FALSE ) //Install IRQ
{
printf("SPI IRQ install error!\n");
while(1);
}
}
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 8