Hi, I try to us LM4F120XL to control AIC3254 codec by SPI. Every time I read the register in AIC3254, I always get "255". Can anyone help? Thanks a lot.
Howard
//*****************************************************************************
//
// This function sets up DAC.
//
//*****************************************************************************
void
DacInit(void)
{
uint32_t pui32DataRx[NUM_SSI_DATA];
//
// The SSI0 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
//
// For this example SSI0 is used with PortA[5:2]. The actual port and
// pins used may be different on your part, consult the data sheet for
// more information. GPIO port A needs to be enabled so these pins can
// be used.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5.
// This step is not necessary if your part does not support pin muxing.
// TODO: change this to select the port/pin you are using.
//
GPIOPinConfigure(GPIO_PA2_SSI0CLK);
GPIOPinConfigure(GPIO_PA3_SSI0FSS);
GPIOPinConfigure(GPIO_PA4_SSI0RX);
GPIOPinConfigure(GPIO_PA5_SSI0TX);
//
// Configure the GPIO settings for the SSI pins. This function also gives
// control of these pins to the SSI hardware. Consult the data sheet to
// see which functions are allocated per pin.
// The pins are assigned as follows:
// PA5 - SSI0Tx
// PA4 - SSI0Rx
// PA3 - SSI0Fss
// PA2 - SSI0CLK
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
GPIO_PIN_2);
//
// Configure and enable the SSI port for SPI master mode. Use SSI0,
// system clock supply, idle clock level low and active low clock in
// freescale SPI mode, master mode, 1MHz SSI frequency, and 8-bit data.
// For SPI mode, you can set the polarity of the SSI clock when the SSI
// unit is idle. You can also configure what clock edge you want to
// capture data on. Please reference the datasheet for more information on
// the different SPI modes.
//
//SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 1000000, 8);
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 1000, 8);
//
// Enable the SSI0 module.
//
SSIEnable(SSI0_BASE);
//
// Read any residual data from the SSI port. This makes sure the receive
// FIFOs are empty, so we don't read any unwanted junk. This is done here
// because the TI SSI mode is full-duplex, which allows you to send and
// receive at the same time. The SSIDataGetNonBlocking function returns
// "true" when data was returned, and "false" when no data was returned.
// The "non-blocking" function checks if there is any data in the receive
// FIFO and does not "hang" if there isn't.
//
while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0]))
{
}
DACReadRegister(0x0);
}
void DACReadRegister(unsigned int ucRegister)
{
uint32_t pui32Data[1];
unsigned int reg;
while(SSIDataGetNonBlocking(SSI0_BASE, &pui32Data[0]))
{
}
pui32Data[0] = 0x0;
//
// Write the first byte to the controller (register)
//
//I2CMasterDataPut(DAC_I2C_MASTER_BASE, ucRegister);
reg = (ucRegister << 1) | 1;
SSIDataPut(SSI0_BASE, reg);
//
// Wait until the current byte has been transferred.
while(SSIBusy(SSI0_BASE))
{
}
//
// Read Data Byte.
//
SSIDataGet(SSI0_BASE, &pui32Data[0]);
//
// Wait until the current byte has been transferred.
while(SSIBusy(SSI0_BASE))
{
}
UARTprintf("read:%d\n", ucRegister);
UARTprintf("%d\n", pui32Data[0]);
}
void DACWriteRegister(unsigned char ucRegister, unsigned long ulData)
{
unsigned int reg;
IntMasterDisable();
//
// Write the first byte to the controller (register)
//
//I2CMasterDataPut(DAC_I2C_MASTER_BASE, ucRegister);
reg = (ucRegister << 1);
SSIDataPut(SSI0_BASE, reg);
//
// Wait until the current byte has been transferred.
//
//while(I2CMasterBusy(DAC_I2C_MASTER_BASE))
while(SSIBusy(SSI0_BASE))
{
}
//
// Write the data byte to the controller.
//
//I2CMasterDataPut(DAC_I2C_MASTER_BASE, ulData);
SSIDataPut(SSI0_BASE, ulData);
//
// Wait until the current byte has been transferred.
//
//while(I2CMasterBusy(DAC_I2C_MASTER_BASE))
while(SSIBusy(SSI0_BASE))
{
}
IntMasterEnable();
}