cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO (chip select) does not go high between SPI sends?

monomonster
Associate II
Posted on June 05, 2015 at 23:41

I'm using SPI3 on an STM32F4, chip select toggled in software. I have a function that sets the chip select low, sends data and than pulls up chip select pin.

Now I've noticed that when this send function is being called several times one after the other, the chip select is not pulled high between the bytes,as should? Can this be related to my GPIO settings for speed or something else maybe?
9 REPLIES 9
Posted on June 06, 2015 at 01:44

Most likely in the coding, and the status bits being waited upon.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
monomonster
Associate II
Posted on June 06, 2015 at 11:58

Can you please elaborate a bit so I'll have a chance to make the most from your comment? Thanks! 🙂

stm32forum
Associate II
Posted on June 06, 2015 at 14:36

Maybe you can share some code, it's hard to help you this way.

How doe you determine the CS pin doesn't change between sends, with a scope?

monomonster
Associate II
Posted on June 06, 2015 at 18:18

Sure, here is the init code from my library. The macros are just to set the pins high and low. They were tested OK, when viewing the output with a logic analyzer I've seen the problem. When there are multiple consecutive sends I don't see the CS going high. After the final send it will go high though.

void MAX5216Init(SPI_HandleTypeDef *hspi)
{
MAX5216_CS_HIGH;
MAX5216_CLR_HIGH;
uint8_t aTxBuffer[]={0x80,0,0};
MAX5216_CS_LOW;
HAL_SPI_Transmit(hspi,(uint8_t*)aTxBuffer,3,1000);
MAX5216_CS_HIGH;
}

Posted on June 07, 2015 at 16:42

How do you ''look'' at the signal in question, is your instrumentation capable of capturing short pulses? What is the output speed setting of the given pin?

JW
monomonster
Associate II
Posted on June 07, 2015 at 19:20 Here are the pin settings I'm using:

/*Configure GPIO pin : PD4 CS*/
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/*Configure GPIO pin : PD7 CLR*/
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

I have a 24MHz capable logic analyzer, just to double check I also used a scope with 25MHz BW.
Posted on June 07, 2015 at 23:52

> I have a 24MHz capable logic analyzer, just to double check I also used a scope with 25MHz

Is that adequate? If you run a 'F4 at cca 160MHz, you can get a cca 6ns pulse.

We haven't seen your macro, nor your back-to-back-write code, not the disassembly of it which is the most interesting. But first, try to add several

http://www.keil.com/pack/doc/cmsis/Core/html/group__intrinsic___c_p_u__gr.html#gac71fad9f0a91980fecafcb450ee0a63e

in between the back-to-back writes and look again.

JW

Mark Edwards
Associate II
Posted on June 08, 2015 at 00:47

I have had similar problems signalling to a FPGA at high speed. Even with the pin speed at max the signal isn’t always guaranteed.

To get around it I wait for the state of the GPIO pin in the IDR register to be correct, when toggling a line just to make sure it has set/cleared, which seems to work.

monomonster
Associate II
Posted on June 08, 2015 at 06:34

I'm not running the MCU that fast, when I set the pins as push/pull the CS pulse width is 0.2 usec that is within spec for sure.

Here is the GPIO toggle macro:

#define MAX5216_CS_LOW HAL_GPIO_WritePin(MAX5216_PORT,MAX5216_CS_PIN,GPIO_PIN_RESET)
#define MAX5216_CS_HIGH HAL_GPIO_WritePin(MAX5216_PORT,MAX5216_CS_PIN,GPIO_PIN_SET)
#define MAX5216_CLR_LOW HAL_GPIO_WritePin(MAX5216_PORT,MAX5216_CLR_PIN,GPIO_PIN_RESET)
#define MAX5216_CLR_HIGH HAL_GPIO_WritePin(MAX5216_PORT,MAX5216_CLR_PIN,GPIO_PIN_SET)

The back to back write code from main is:

MAX5216Init(&hspi3);
MAX5216Write(&hspi3,32000);

I'm wondering how come this is so complicated. I used AVRs for years and wrote SPI libraries for 8051 and 8086 and it was always simple. I have no idea what is going on here...