This is my new setup function:
Code: Select allvoid spi_init()
{
volatile AT91PS_SPI pSPI = AT91C_BASE_SPI; // Pointer to SPI data structure
volatile AT91PS_PMC pPMC = AT91C_BASE_PMC; // Pointer to PMC data structure
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; // Pointer to PIO data structure
AT91F_SPI_Reset(pSPI); // software reset
AT91F_SPI_CfgPMC(); // enable SPI peripheral clock
// All I/O lines are inputs with the pullup enabled at rest (burn that into memory)
AT91C_BASE_PIOA->PIO_OER = BIT13 | BIT14; //BIT13=MOSI=output, BIT14=SPICLK=output
AT91C_BASE_PIOA->PIO_PPUDR = BIT13 | BIT14;
pPIO->PIO_PDR = BIT12 | BIT13 | BIT14; //Set PIO to NOT use the SPI pins. PA12_MISO PA13_MOSI PA14_SPCK
pPIO->PIO_ASR = BIT12 | BIT13 | BIT14; //Set Alternate PIO A for SPI pins.
// Setup mode register
pSPI->SPI_MR = AT91C_SPI_MSTR // Enable master mode
| AT91C_SPI_PS_VARIABLE // Watch out for this... We want the features but we arnt using the pins...
| AT91C_SPI_MODFDIS; // Disable mode fault detection
// this needs to be fixed // AT91F_SPI_DisableIt(pSPI); // All interupts are off
// Setup Chip Select Register for flash memory
pSPI->SPI_CSR[0] = AT91C_SPI_NCPHA // SPI Bus Protocol Mode 0 (The AT26F004 supports modes 0 and 3)
| AT91C_SPI_BITS_8 // 8 bit data transfers
| ((2<<8) & AT91C_SPI_SCBR) // Baud Rate = MCK/SCBR = 24MHz (The AT26F004 supports a maximum of 33MHz)
| ((6<<16) & AT91C_SPI_DLYBS) // Dont know about this one,
| ((6<<24) & AT91C_SPI_DLYBCT); // or this one yet...
// Enable SPI
AT91F_SPI_Enable(pSPI);
}
When I use this:
Code: Select allvoid spi_send(unsigned char ss_num, unsigned int data)
{
volatile AT91PS_SPI pSPI = AT91C_BASE_SPI;
AT91F_SPI_PutChar(pSPI, 'U', 1); // lets see if this works for now?
//while(!(pSPI->SPI_SR & (AT91C_SPI_TDRE))); //wait for a clear transmit register
//pSPI->SPI_TDR = ((data & 0xFFFF) | (ss_num<<16)); //assign the transmit register plus the chip select
}
to initiate a transfer I get nothing.
Here is where I think the problem is. I have two slave devices connected to the processor. Neither one of them are using the designated chip select pins but are instead using GPIO. The chip select pins are already being used for other things. Don't ask my why, the hardware designer doesn't really remember why he did it this way either.
I would like to take avantage of the features available in variable chip select such as writing to bits 19:16 in the transmit data register during a transmission in order to determine the configuration of the SPI port but I am not sure how given my current setup.
As you can see in my setup code I do not pass control of the chip select pins to the SPI port so I am wondering if that is why I am not seeing a transmission when I call my send function.
Does anyone know if I can still use variable chip select mode while still using the dedicated chip select pins for things other than SPI?