2015-06-05 02:41 PM
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?2015-06-05 04:44 PM
Most likely in the coding, and the status bits being waited upon.
2015-06-06 02:58 AM
Can you please elaborate a bit so I'll have a chance to make the most from your comment? Thanks! :)
2015-06-06 05:36 AM
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?2015-06-06 09:18 AM
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;
}
2015-06-07 07:42 AM
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?
JW2015-06-07 10:20 AM
/*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.
2015-06-07 02:52 PM
> 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 in between the back-to-back writes and look again. JW2015-06-07 03:47 PM
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.2015-06-07 09:34 PM
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...