HOW to send 16bit over SPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-21 05:26 AM
Hi,
I want to send five,16 bit data over SPI. WHile executing the code i cant see any transmission. What i wanted is
- SS = 0 -> 16 bit data1 -> SS=1, SS = 0 -> 16 bit data2 -> SS=1,
or
2, SS=0 , word0, word1, word2,word3, word4 ss=1
i tried both methods but no action..
How to configure FifoThreshold and NSS. DDS_CS_Pin is CS and is connected to PD14
HAL_GPIO_WritePin(GPIOD,DDS_CS_Pin,0);
HAL_Delay(1);
HAL_SPI_Transmit(&hspi6, (uint8_t*)&DDS_CR, 2, 10);
HAL_SPI_Transmit(&hspi6, (uint8_t*)&DDS_FL, 2, 10);
HAL_SPI_Transmit(&hspi6, (uint8_t*)&DDS_FH, 2, 10);
HAL_SPI_Transmit(&hspi6, (uint8_t*)&DDS_PR, 2, 10);
HAL_SPI_Transmit(&hspi6, (uint8_t*)&DDS_RST,2, 10);
HAL_Delay(1);
HAL_GPIO_WritePin(GPIOD,DDS_CS_Pin,1);
static void MX_SPI6_Init(void)
{
hspi6.Instance = SPI6;
hspi6.Init.Mode = SPI_MODE_MASTER;
hspi6.Init.Direction = SPI_DIRECTION_2LINES_TXONLY;
hspi6.Init.DataSize = SPI_DATASIZE_16BIT;
hspi6.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi6.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi6.Init.NSS = SPI_NSS_SOFT;
hspi6.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi6.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi6.Init.TIMode = SPI_TIMODE_DISABLE;
hspi6.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi6.Init.CRCPolynomial = 7;
hspi6.Init.NSSPMode = SPI_NSS_SOFT;
hspi6.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi6.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi6.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi6.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi6.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi6.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi6.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi6.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi6.Init.IOSwap = SPI_IO_SWAP_DISABLE;
if (HAL_SPI_Init(&hspi6) != HAL_OK)
{
Error_Handler();
}
}
its SPI is waiting for FIFO threshold and what is the threshold for follwoing ?
hspi6.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
Solved! Go to Solution.
- Labels:
-
SPI
-
STM32Cube MCU Packages
-
STM32H7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-21 05:45 AM
>>HAL_SPI_Transmit(&hspi6, (uint8_t*)&DDS_CR, 2, 10);
Will observed that the count here is units of DataSize
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-21 06:26 AM
With the FIFO, you can actually stay in 8 bit SPI mode and write a 16 bit value in the DR.
they will be sliced in 2x8 by HW. only thing to take care is MSB/LSB ordering.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-21 05:45 AM
>>HAL_SPI_Transmit(&hspi6, (uint8_t*)&DDS_CR, 2, 10);
Will observed that the count here is units of DataSize
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-21 06:26 AM
With the FIFO, you can actually stay in 8 bit SPI mode and write a 16 bit value in the DR.
they will be sliced in 2x8 by HW. only thing to take care is MSB/LSB ordering.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-22 12:40 AM
Thank you...
I tried both 8 and 16 bit, TI and Motorola, But No use.. Then i Put the transmission in an 0.5sec loop and observed transaction... but My DDS does not updated... used NSS and without NSS... Then i wrote the following program, it worked. AD9837 updated the regs and produced sine wave... So i think the SPI is waiting for some BUffer Fill up or threshold... and can't find any such thing other than FIFO threshold(which i tried)...
Any Information?
Next i want to interface 24bit 6 channel Sigma delta adc for which this 'trick' may not work...
I want to read all regs and set regs init almost 3 SPS...
I have a mind block to use DMA ,due to lack of knowledge and tickets raised here related to DMA issues...
How it is safe to use DMA ?
HAL_GPIO_WritePin(GPIOA,sck_Pin,1);
HAL_GPIO_WritePin(GPIOD,cs_Pin,0);
ShifT(0);
ShifT(0);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
//FL = 0x50c7;
ShifT(0);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
//FH = 0x400f;
ShifT(0);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(1);
ShifT(1);
ShifT(1);
ShifT(1);
//PR = 0xc000;
ShifT(1);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
//RST =0x2000;
ShifT(0);
ShifT(0);
ShifT(1);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
ShifT(0);
HAL_GPIO_WritePin(GPIOA,sck_Pin,1);
HAL_Delay(1);
HAL_GPIO_WritePin(GPIOD,cs_Pin,1);
HAL_GPIO_WritePin(GPIOA,mosi_Pin,1);
***************
void ShifT(int n)
{
if (n==0)
{
HAL_GPIO_WritePin(GPIOA,mosi_Pin,0); // 0
}
else
{
HAL_GPIO_WritePin(GPIOA,mosi_Pin,1); // 0
}
DWT_Delay(10);
HAL_GPIO_WritePin(GPIOA,sck_Pin,0);
DWT_Delay(10);
HAL_GPIO_WritePin(GPIOA,sck_Pin,1);
DWT_Delay(10);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-22 02:13 PM
I would recommend to use SPIS1, SPIS2 or SPIS3 because they have a 16 Bit FIFO.
SPI4..6 just have 8 Bit only.
Please read the documentation on page 2133 and 2134 in the Reference Manual RM0433 concerning half-duplex communication.