AnsweredAssumed Answered

Internal Working of SPI?

Question asked by Sandeep Dhokne on Jul 26, 2017
Latest reply on Aug 1, 2017 by David Littell

Hi,

 

When i checked on DSO  (scope)  i found that after chip select SPI_NSS latch to ground.

there in clock signals on clk pin.

there is no data on SI and SO pin.

 

Why there no data on SPI's Pin?

Why SPI_NSS latch to ground? 

 

Anybody please help.

What is the internal working of HAL SPI protocol?

 

Initialization of SPI

 

void MX_SPI1_Init(void)
{

hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
hspi1.Init.CRCPolynomial = 10;
HAL_SPI_Init(&hspi1);

}

 

My Code:

void InitMemory(void)
{
PageAdd = 0; 
ByteAdd = 0;
ByteCount = 1;
ReadMemory(&TotalReportNo, PageAdd, ByteAdd, ByteCount);
ReportNo = TotalReportNo + 1;
}

 

void ReadMemory(UCHAR *bData, UINT PageId, UINT ByteId, UINT NoOfBytes)
{
int Status;
Status = 1;
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
while(Status != HAL_OK)
{
Status = HAL_SPI_TransmitReceive(&hspi1,(uint8_t*)(0xd2),(uint8_t*)(&aRxBuffer),1,1000);
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
while(Status != HAL_OK)
{
Status = HAL_SPI_TransmitReceive(&hspi1,(uint8_t*)((UCHAR)((PageId>>7) & 0xFF)),(uint8_t*)(&aRxBuffer),1,1000);
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
while(Status != HAL_OK)
{
Status = HAL_SPI_TransmitReceive(&hspi1,(uint8_t*)((UCHAR)((PageId<<1)|(ByteId>>8)) & 0xFF),(uint8_t*)(&aRxBuffer),1,1000);
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
while(Status != HAL_OK)
{
Status = HAL_SPI_TransmitReceive(&hspi1,(uint8_t*)((UCHAR)(ByteId & 0xFF)),(uint8_t*)(&aRxBuffer),1,1000);
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
while(Status != HAL_OK)
{
Status = HAL_SPI_TransmitReceive(&hspi1,(uint8_t*)(0x00),(uint8_t*)(&bData),NoOfBytes,1000);
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
}

 

 

Thank you.

Outcomes