cancel
Showing results for 
Search instead for 
Did you mean: 

Problem to communicate with magnetic encoder SSI, in using SPI

erwan
Associate
Posted on April 29, 2014 at 09:34

Hello,

I am working on the AEAT-6600 for 2 weeks and i have problem to communicate with. Indeed, I did the right circuit for Normal mode in the datasheet at the link : http://www.avagotech.com/pages/en/motion_control_encoder_products/magnetic_encoders/aeat-6600-t16/    and i never programmed it, so he should communicate with SSI in slow mode with 10bits resolution as says in the Application Note. I use a Stm32l100RC-discovery board to communicate with. I saw on the application note that this SSI 3wire is compatible with SPI and only i have in output of the sensor is 0 or random values like 65535 and 32768 if i disable internally pull-down of my microchip pins.

I saw on the datasheet that the new data is available after a half clock cycle and not an entire cycle. My clock is high when idle as the datasheet wants and in Normal mode I only connects MISO to DO/DI of the sensor. The AEAT-6600 is in 3.3V operation mode. I know the sensor is working because the MAG-HI and MAG-LO pins work well but I don't know how to use STM32L100 SPI with SSI's sensor. Can you tell me what is wrong in my code?

Here is my code to configure and communicate with :

/*------------------------------------------------------------------------

 * Peripheral SPI 1

 * -----------------------------------------------------------------------

 * Device Wind Angle by AEAT660

 * SClk PA5

 * MISO PA6

 * MOSI PA7

 * SS1 PC10

 * Clock 32 MHz

 * -----------------------------------------------------------------------*/

// this function initializes the SPI1 peripheral

void init_SPI1(void){

GPIO_InitTypeDef GPIO_InitStruct;

SPI_InitTypeDef SPI_InitStruct;

// enable clock for used IO pins

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

/* configure pins used by SPI1

* PA5 = SCK

* PA6 = MISO

* PA7 = MOSI

*/

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6 | GPIO_Pin_5;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;

GPIO_Init(GPIOA, &GPIO_InitStruct);

// connect SPI1 pins to SPI alternate function

GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);

// enable clock for used IO pins

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

/* Configure the chip select pin

  in this case we will use PC10 */

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(GPIOC, &GPIO_InitStruct);

GPIOC->BSRRL |= GPIO_Pin_10; // set PC10 high

// enable peripheral clock

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

/* configure SPI1 in Mode 0 

* CPOL = 1 --> clock is high when idle

* CPHA = 0 --> data is sampled at the first edge

*/

SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // set to full duplex mode, seperate MOSI and MISO lines

SPI_InitStruct.SPI_Mode = SPI_Mode_Master;     // transmit in master mode, NSS pin has to be always high

SPI_InitStruct.SPI_DataSize = SPI_DataSize_16b; // one packet of data is 16 bits wide

SPI_InitStruct.SPI_CPOL = SPI_CPOL_High;        // clock is high when idle

SPI_InitStruct.SPI_CPHA = SPI_CPHA_2Edge;      // data sampled at first edge

SPI_InitStruct.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Set; // set the NSS management to internal and pull internal NSS high

SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; // SPI frequency is APB2 frequency / 256 pour �tre <1MHz qui est la fmax du capteur

SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;// data is transmitted MSB first

SPI_Init(SPI1, &SPI_InitStruct); 

SPI_Cmd(SPI1, ENABLE); // enable SPI1

}

/*------------------------------------------------------------------------

 * Function SPI1_send

 * -----------------------------------------------------------------------

 * @descr Send 16bits via SPI 1

 * @param data

 * @retval received data from SPI data register

 * -----------------------------------------------------------------------*/

/* This funtion is used to transmit and receive data 

 * with SPI1

 * data --> data to be transmitted

 * returns received value

 */

uint16_t SPI1_send(uint16_t data){

/* Check the parameters */

  assert_param(IS_SPI_ALL_PERIPH(SPI1));

SPI1->DR = data; // write data to be transmitted to the SPI data register

while( !(SPI1->SR & SPI_I2S_FLAG_TXE) ); // wait until transmit complete

while( !(SPI1->SR & SPI_I2S_FLAG_RXNE) ); // wait until receive complete

while( SPI1->SR & SPI_I2S_FLAG_BSY ); // wait until SPI is not busy anymore

return SPI1->DR; // return received data from SPI data register

}

/* Private functions ---------------------------------------------------------*/

/**

  * @brief  Main program.

  * @param  None

  * @retval None

  */

int main(void)

{

/**** Variables ****/

uint16_t received_val = 0;

/* Initialise la clock et les peripheriques ----------------------------*/

  HwInit();

printf(''_n\r ************ Mode NORMAL ************'');

//STM_EVAL_LEDOn(LED4);

GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_SET); // set PC10 (NCS) High

GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_RESET); // set PC10 (NCS) Low

printf(''\n\r Val de PC10 : %d'',GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10));

Delay(2000);  //2ms of waiting

// transmit dummy byte and receive data

received_val = SPI1_send(0x0000);

GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_SET); // set PC10 (NCS) High

printf(''\n\r La valeur du capteur est %d'',received_val);

Delay(2000000); //2 seconds of waiting

GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_RESET); // set PC10 (NCS) Low

printf(''\n\r Val de PC10 : %d'',GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_10));

//Delay(2000);

received_val = SPI1_send(0x0000);

printf(''\n\r La valeur 2 du capteur est %d'',received_val);

GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_RESET); // set PC10 (NCS) High

Delay(2000000);

}

#stm32l1xx #spi #stm32 #ssi #ssi-spi
3 REPLIES 3
francescatodiego
Associate II
Posted on April 29, 2014 at 12:26

Hi,

my expereince

with

SSI encoders

SSI have a MIN read frequency under this minimal frequency first clock front start read but SSI interface go in timeout state before next clock front and the next front start a new read

(Always first SSI output bit is 1)

Check also the ouptut data format, counter size, data alignement ecc...

I add also a pdf where is well explained the SSI interface (see attachments)

________________

Attachments :

SSI_Interface.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I14G&d=%2Fa%2F0X0000000bhm%2F.yPLsLSLi3kPtqAYTqH3UGNuWlCqo9_cGTdd6.43s3M&asPdf=false
erwan
Associate
Posted on May 13, 2014 at 18:02

Hi diego,

I thought we had a mail when a reply come to the topic so I only see it 15 days later...

Thank you for your pdf, I will read it carefully and go back to this part of my project.

If I well understood your reply, my SPI frenquency seems to be too slow for the encoder?

The datasheet says that SSI transfers are on 16 bits, but by default, without programming the output data are on 10bits. Maybe in this case some bits must be removed after reception...

I will reply later if i have news,

Erwan

Posted on May 13, 2014 at 18:47

If I well understood your reply, my SPI frenquency seems to be too slow for the encoder?

And what frequency is that? If the APB is 32 MHz, I'd guess you're at 125 KHz, the part is rated for a 1 MHz (1000 KHz)

The other is the inter-transmission delay, or 20 uS (50 KHz)

You could also try using the pins in GPIO mode, and try bit banging the interface, and confirming what you are seeing, and examining what's coming back with a scope or logic analyzer.

Also try NOT to exit main(), try looping so you can see signals on a scope.

Yes, the forum does not alert, and doesn't let you review post history either.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..