2015-12-11 03:20 AM
Hi folks,
I am wondering how to interface an encoder sensor using SSI interface on my STM32. I didn't find any product with integrated SSI interface.The encoders provides 18-bit frame as describes in datasheet (see http://ams.com/eng/Products/Position-Sensors/Linear-Magnetic-Position-Sensors/AS5311).Is it possible to use the SPI interface to read the sensor ?Have you application notes or example codes about that ?I am looking for an accurate way to read my encoder hence ''bit-banging'' is not a solution. Thanks for your help. #spi #ssi #stm322015-12-11 03:32 AM
First, it is very easy to make software SPI, with any data size you want. And in some times it can be as fast as your hardware SPI, if you don't use any DMA or something like that.
Second, some MCU's can use 9b data size, so so you will have to call two times to get 18 edges ( like STM32F3 , STM32F7 does have variable length of SPI 4 to 16b) SSI its simply to avoid SPI name due to trademark i guess ( Like SMB, SPORT and so on) This is software SPI, works for me, when i have multiple devices with different data and command size :uint8_t sFLASH_SendByte(uint8_t byte)
{
uint8_t data = 0;
register uint16_t i = 0;
register uint32_t delay = 0x1;
data = 0;
while(i<
8
)
{
GPIO_ResetBits(GPIOB, GPIO_Pin_3);
if(((byte<<i)&0x80)==0x80)
GPIO_SetBits(GPIOB, GPIO_Pin_5);
else
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
Delay(delay);
GPIO_SetBits(GPIOB, GPIO_Pin_3);
Delay(delay);
if((GPIOB->IDR & GPIO_Pin_4)==GPIO_Pin_4)
data+=0x80>>i;
GPIO_ResetBits(GPIOB, GPIO_Pin_3);
i++;
}
return data;
}
2015-12-11 05:23 AM
Hi Linas,
As mentioned before, I really need an efficient hardware handling of my SSI sensor. Indeed, my application is multiple motors control (FOC) and I plan to had other feature so CPU load for SSI handling have to be as low as possible.Using 9-bit SPI frame could be a very good solution. Moreover, I work with STM32F303 which provides the variable length SPI feature. Does anyone have already experiment this solution ?I would prefer to be sure SSI will work before order the sensor, hence I cannot perform simple test on my STM32F303.2015-12-11 08:45 AM
''Does anyone have already experiment this solution ?''
If you going to read sensor with software by using SPI peripheral, and it offers 9b data packet, it will work, no question. Tricky part would be make it work with DMA, since DMA can't generate chip select, you have to use PWM or something for that.2015-12-11 11:59 AM
You could use SPI peripheral on any STM32 uC for SSI communication.
You will have to connect 3 lines (CLK, DO and CS). CS on encoder side should be connected on one GPIO output on your uC. If you configured DMA for transfer, you should set the number of transfers. Let say 3x of one byte. Also, read the manual of the encoder, for how long you should wait after falling edge on CS line. After that delay, you start clocking by enabling bits RXDMAEN and TXDMAEN. When TCIF (transfer complete flag) rises, all data was transferred and you can put CS line back up.I advise you to read STM reference manual (SPI section) too.2015-12-12 10:44 AM
I don't see any point of using DMA for single readout. If clock can be high, you will not win any time by doing that. If data was like 100 or more points, yes, that will be better, if you have interrupt based program, where you need CPU time for many tasks