SPI-2 - Spi Transaction Completed

srjasz
Posts: 46
Joined: Wed Apr 03, 2024 4:29 pm

SPI-2 - Spi Transaction Completed

Postby srjasz » Wed Jun 05, 2024 2:43 pm

I need to determine when a SPI transaction has completed. The SPI is transferring single 8 bit message each transaction and doing it in polling mode. There is a SPI_TRANS_DONE interrupt and I am able to read its flag. The problem is that it triggers on the when the Chip Select gets activated, which is after initiating SPI_START and before the transaction actually occurs. The name SPI_TRANS_DONE would indicate that it would be triggered at the end of the transaction when the Chip Select is de-activate but that is not the case. The API doesn't check to see if the transaction has completed and simply waits for a loop timer to expire. Is there any mechanism to determine if the SPI transaction has actually complted?

Thanks

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: SPI-2 - Spi Transaction Completed

Postby ESP_Sprite » Fri Jun 07, 2024 1:02 am

Do you happen to have code to replicate that?

srjasz
Posts: 46
Joined: Wed Apr 03, 2024 4:29 pm

Re: SPI-2 - Spi Transaction Completed

Postby srjasz » Mon Jun 10, 2024 3:03 pm

Yes, Sorry but I don't know how to put it in one of those cool code windows. I use IO pin 10 to trigger the oscilloscope.

CmGpioDedicatedClr10(); // Set IO 10 low.
*SPI_Cmd_Reg_2 = SPI_CMD_REG_USR; // Start the SPI.
while(!((*SPI_Dma_Int_Raw_Reg_2) & SPI_DMA_INT_RAW_BIT_TRANS_DONE)){}; // Wait for Trans done to go high.
CmGpioDedicatedClr10(); // Set IO 10 high.

MicroController
Posts: 1704
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: SPI-2 - Spi Transaction Completed

Postby MicroController » Mon Jun 10, 2024 6:20 pm

Do you clear the interrupt flag before starting a transaction?

srjasz
Posts: 46
Joined: Wed Apr 03, 2024 4:29 pm

Re: SPI-2 - Spi Transaction Completed

Postby srjasz » Mon Jun 10, 2024 8:11 pm

Yes, forgot to post that. After the

*SPI_Cmd_Reg_2 = SPI_CMD_REG_USR; // Start the SPI.

it takes about 200ns before the interrupt flag gets set which is about 220 to 240ns before the transaction completes.

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: SPI-2 - Spi Transaction Completed

Postby ESP_Sprite » Tue Jun 11, 2024 5:38 am

On which chip is this?

MicroController
Posts: 1704
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: SPI-2 - Spi Transaction Completed

Postby MicroController » Tue Jun 11, 2024 10:24 am

srjasz wrote:
Mon Jun 10, 2024 8:11 pm
Yes, forgot to post that. After the

*SPI_Cmd_Reg_2 = SPI_CMD_REG_USR; // Start the SPI.

it takes about 200ns before the interrupt flag gets set which is about 220 to 240ns before the transaction completes.
Ok, so you cleared the interrupt by writing a 1 to its bit in the ...INT_RAW_REG or ...INT_CLR_REG? - And the pointers you're using (SPI_Cmd_Reg_2, SPI_Dma_Int_Raw_Reg_2) are all declared as pointers to volatile?
Last edited by MicroController on Tue Jun 11, 2024 1:56 pm, edited 1 time in total.

srjasz
Posts: 46
Joined: Wed Apr 03, 2024 4:29 pm

Re: SPI-2 - Spi Transaction Completed

Postby srjasz » Tue Jun 11, 2024 1:42 pm

Correct, I wrote a 1 to the clear register.

Here are my pointer declarations.

volatile int32_t *SPI_Cmd_Reg_2 = (volatile int32_t *)0x60024000L;

volatile int32_t *SPI_Clock_Reg_2 = (volatile int32_t *)0x6002400CL;
volatile int32_t *SPI_User_Reg_2 = (volatile int32_t *)0x60024010L;
volatile int32_t *SPI_User1_Reg_2 = (volatile int32_t *)0x60024014L;
volatile int32_t *SPI_User2_Reg_2 = (volatile int32_t *)0x60024018L;
volatile int32_t *SPI_Ms_Dlen_Reg_2 = (volatile int32_t *)0x6002401CL;
volatile int32_t *SPI_Misc_Reg_2 = (volatile int32_t *)0x60024020L;
volatile int32_t *SPI_Dma_Int_Clr_Reg_2 = (volatile int32_t *)0x60024038L;
volatile int32_t *SPI_Dma_Int_Raw_Reg_2 = (volatile int32_t *)0x6002403CL;
volatile int32_t *SPI_Dma_Int_St_Reg_2 = (volatile int32_t *)0x60024040L;

Thanks for helping.

MicroController
Posts: 1704
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: SPI-2 - Spi Transaction Completed

Postby MicroController » Tue Jun 11, 2024 6:34 pm

Looks all right to me. Haven't checked the addresses though.
We may have to look more deeply into the chip specifics, as @ESP_Sprite implied. So, which SoC are you using?

User avatar
ok-home
Posts: 78
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: SPI-2 - Spi Transaction Completed

Postby ok-home » Wed Jun 12, 2024 7:29 am

I would also specify
which spi mode is DMA or CPU ?
full duplex or half duplex ?

Who is online

Users browsing this forum: espmpo, Google [Bot] and 90 guests