Forum Discussion
Altera_Forum
Honored Contributor
9 years agoHi ask
I have the same issue as you described in this thread. How did you manage to get it to work? I'm not using Linux but uCos, but I still can't make the SPI controller start transmitting data. It just puts the data into the FIFO buffer. I have verified that my pin mapping is correct: - CS pin can be toggled (Can be set low by SPI controller or by PIO CS pin, both works) - SS pin can be toggled (selecting SPI mode 0 or 3). I can break in my code and using the debugger I can select another SPI frameformat (TI instead of Motorola). After this "trick" I can write data into the DR register and data gets transmitted (until SPI driver is disabled/enabled again). Here is my init function:ALT_STATUS_CODE FramDriver_Init(ALT_SPI_CTLR_t eAltSPIModNum){
static uint8_t u8RunOnce = 1;
ALT_STATUS_CODE eAltStatusCode = ALT_E_SUCCESS;
ALT_SPI_CONFIG_t cfg =
{
.frame_size = ALT_SPI_DFS_8BIT,
.frame_format = ALT_SPI_FRF_SPI,
.clk_phase = ALT_SPI_SCPH_TOGGLE_START,
.clk_polarity = ALT_SPI_SCPOL_INACTIVE_HIGH,
.transfer_mode = ALT_SPI_TMOD_TXRX,
.loopback_mode = false,
.slave_output_enable = true
};
// Make sure CS pin is high before initializing SPI peripheral. Is also pulled up externally...
SET_CS_PIN_HIGH;
if (1 == u8RunOnce)
{
u8RunOnce = 0;
eAltStatusCode = alt_spi_init(eAltSPIModNum, &stAltSPIdevice);
}
eAltStatusCode = alt_spi_disable(&stAltSPIdevice);
if (eAltStatusCode == ALT_E_SUCCESS)
{
eAltStatusCode = alt_spi_config_set(&stAltSPIdevice, &cfg);
}
if (eAltStatusCode == ALT_E_SUCCESS)
{
eAltStatusCode = alt_spi_speed_set(&stAltSPIdevice, SPI_SPEED);
}
if (eAltStatusCode == ALT_E_SUCCESS)
{
eAltStatusCode = alt_spi_slave_select_enable(&stAltSPIdevice, SPI_SLAVE_DEVICE);
}
if (eAltStatusCode == ALT_E_SUCCESS)
{
eAltStatusCode = alt_spi_enable(&stAltSPIdevice);
}
return eAltStatusCode;
}
Here is my write function: ALT_STATUS_CODE FramDriverReadStatusRegister(uint8_t *uip8Status){
ALT_STATUS_CODE eAltStatusCode = ALT_E_SUCCESS;
const uint16_t au16TxOpCodeBuffer = {(uint16_t)OP_CODE_RDSR, 0x0000};
uint16_t au16RxBuffer = {0x0000, 0x0000};
// Check if SPI is initialized!
if (0 == stAltSPIdevice.location)
{
// SPI is not initialized -> Return BAD_OPERATION
return ALT_E_BAD_OPERATION;
}
// Handle CS pin manually!!!
SET_CS_PIN_LOW;
// Debug
alt_spi_int_clear(&stAltSPIdevice, ALT_SPI_STATUS_TXEI);
alt_spi_int_clear(&stAltSPIdevice, ALT_SPI_STATUS_RXUI);
alt_spi_int_clear(&stAltSPIdevice, ALT_SPI_STATUS_ALL);
// Write Op Code for Read Status register (OP_CODE_RDSR)
eAltStatusCode = alt_spi_tx_fifo_enq(&stAltSPIdevice, au16TxOpCodeBuffer);
// Wait for FIFO to be empty
while(ALT_E_TRUE != alt_spi_tx_fifo_is_empty(&stAltSPIdevice));
// Wait for transfer to complete! -> Poll busy flag!
while (ALT_E_TRUE == alt_spi_is_busy(&stAltSPIdevice));
// Read back Status Register from device (Size is specified to 1 byte)
eAltStatusCode = alt_spi_rx_fifo_deq(&stAltSPIdevice, au16RxBuffer);
// Return status register in uip8Status
*uip8Status = (uint8_t) (au16RxBuffer & 0x00FF);
// Handle CS pin manually!!!
SET_CS_PIN_HIGH;
return eAltStatusCode;
}
I have read all manuals for HPS and Cyclone V regarding SPI and TX should start if the following conditions are met: --- Quote Start --- The SPI master starts data transfers when all the following conditions are met: • The SPI master is enabled • There is at least one valid entry in the transmit FIFO buffer • A slave device is selected --- Quote End --- I can see all three conditions in my SPI status registers, but still no output. Any help would be appreciated! Best regards Brian P.S. I tried the command sequence above from u-boot, but I can't make it write out data...