Content originally posted in LPCWare by TKoe on Thu Nov 22 03:32:28 MST 2012
Hello!
I have configured an LPC1788 as SPI master on SSP0 (CPOL = 1; CPHA = 0) to communicate with a DAC chip at 30 MHz.
This chip needs the chip select pulled down (I do that with a GPIO), then three bytes of command data need to be transmitted and then the chip select needs to be pulled up again.
So to send any data I use the SSP_ReadWrite function and the data does get transmitted and the DAC updates its outputs accordingly. So everything's fine... except for one thing:
The three bytes that I transmit with this function aren't sent directly after another (as I would have expected) but between each byte there's a pause of about one or two microseconds. Below is the code that will transmit one of those three-byte-packages.
Also between two packages there's a pause of over TEN microseconds.
My question is: Why are there so long pauses and how would I go to reduce/remove them? Any hints are greatly appreciated!
Regards!
<code>
void setdac(t_dac_channel ch, uint16_t value)
{
uint8_t tx_data[3] = {0,0,0};
uint8_t rx_data[6];
tx_data[0] =
(0 << 7) |
(0 << 6) |
(0 << 5) |
(1 << 4) |
(0 << 3) |
((ch >> 2) & 1) |
((ch >> 1) & 1) |
((ch >> 0) & 1) ;
tx_data[1] = (value >> 8) & 0xFF;
tx_data[2] = (value >> 0) & 0xFF;
SSP_DATA_SETUP_Type ssp_data =
{
.tx_data = tx_data,
.tx_cnt = 3,
.rx_data = rx_data,
.rx_cnt = 3,
.length = 3,
.status = 0,
};
SPI_GPIO_PORT->MASK = ~(1 << SPI_SSEL_PIN);
GPIO_ClearValue(SPI_PORT, 1 << SPI_SSEL_PIN); // pull down
SSP_ReadWrite(SPI_CH, &ssp_data, SSP_TRANSFER_POLLING);
while (!(SPI_CH->SR & 0x01)); // 0x01 == TFE (Transmit FIFO Empty)
GPIO_SetValue(SPI_PORT, 1 << SPI_SSEL_PIN); // pull up
}
</code>