cancel
Showing results for 
Search instead for 
Did you mean: 

How to read Device ID Register in IDE

james99maher
Associate II
Posted on November 14, 2016 at 22:47

I am using an STM32VLDISCOVERY with an accelerometer which is connected using SPI. I am trying to determine whether or not I have it connected to the STM correctly so I am trying to read its Device ID through the terminal of the IDE I am using (Atollic TrueStudio) but I cannot figure out how to make it work. I have the STM connected via USB but cannot seem to make the STM function as a COM port.

Can somebody please point me in the right direction? Thanks.
9 REPLIES 9
slimen
Senior
Posted on November 15, 2016 at 13:00

Hi,

Refer to the “Device electronic signature� section, “unique device ID register (96 bits)� paragraph in your related reference manual

http://www.st.com/content/ccc/resource/technical/document/reference_manual/a2/2d/02/4b/78/57/41/a3/CD00246267.pdf/files/CD00246267.pdf/jcr:content/translations/en.CD00246267.pdf

to have idea about the unique device identifier.

You can refer to this manual

http://www.st.com/content/ccc/resource/technical/document/user_manual/24/df/3a/30/73/31/4e/9b/CD00283787.pdf/files/CD00283787.pdf/jcr:content/translations/en.CD00283787.pdf

: Developing your STM32VLDISCOVERY applicationusing the Atollic TrueSTUDIO® software.

Hope this helps you.

Regards

james99maher
Associate II
Posted on November 22, 2016 at 23:42

Hey thanks for your reply (sorry for my own delay!).

I'm still confused about this. I'm really not sure how to go about reading the register, it isn't something I've had to do. I've only used the STM32 functionally, if you know what I mean. If you could point me a bit more in the direction I would really appreciate it.

Posted on November 23, 2016 at 05:55

So you're not looking at the STM32 Unique ID, but rather a response from an SPI device that identifies it.

Perhaps you should expand a little on exactly what part it is you are using, and how it is connected, ie pins, SPI#, etc. Review some of the SPI FLASH examples for this and other STM32 family parts.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
james99maher
Associate II
Posted on November 23, 2016 at 19:40

So it's SPI1 I'm using. For that, I have PA5 connected as SCK, PA6 as MISO, PA7 as MOSI, PA0 is Int1 (I intend to use the botton as the interrupt), and PA4 is NSS. The device I'm using is the ADXL362z, and I've looked at the data sheet for the device ID, but it doesn't say anything about how I should go about accessing it... I'm very new to all this so even tasks which appear simple take a long time to figure out for me

Posted on November 23, 2016 at 21:32

The document does go into some detail 

http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf

You'd need to send the byte sequence 0x0B,0x02,0xFF, the 0xFF is a dummy byte, but the Part ID should be returned, the 0x02 is the PARTID register number.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 23, 2016 at 21:40

Something like this should work,

#define ACCEL_SPI SPI1
#define ACCEL_DUMMY_BYTE 0xFF
/**
* @brief Select ACCEL: Chip Select pin low
*/
#define ACCEL_CS_LOW() GPIO_ResetBits(GPIOA, GPIO_Pin_4)
/**
* @brief Deselect ACCEL: Chip Select pin high
*/
#define ACCEL_CS_HIGH() GPIO_SetBits(GPIOA, GPIO_Pin_4)
/**
* @brief Initializes the peripherals used by the SPI ACCEL driver.
* @param None
* @retval None
*/
void ACCEL_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
ACCEL_LowLevel_Init(); /* Pins */
/*!< Deselect the ACCEL: Chip Select high */
ACCEL_CS_HIGH();
/*!< SPI configuration */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(ACCEL_SPI, &SPI_InitStructure);
/*!< Enable the ACCEL_SPI */
SPI_Cmd(ACCEL_SPI, ENABLE);
}
/**
* @brief Sends a byte through the SPI interface and return the byte received
* from the SPI bus.
* @param byte: byte to send.
* @retval The value of the received byte.
*/
uint8_t ACCEL_SendByte(uint8_t byte)
{
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(ACCEL_SPI, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI1 peripheral */
SPI_I2S_SendData(ACCEL_SPI, byte);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(ACCEL_SPI, SPI_I2S_FLAG_RXNE) == RESET);
/*!< Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(ACCEL_SPI);
}
/**
* @brief Reads ACCEL identification.
* @param None
* @retval ACCEL identification
*/
uint8_t ACCEL_ReadID(void)
{
uint8_t Temp = 0;
/*!< Select the ACCEL: Chip Select low */
ACCEL_CS_LOW();
/*!< Send read register instruction */
ACCEL_SendByte(0x0B);
/*!< Send PARTID register */
ACCEL_SendByte(0x02);
/*!< Read a byte from the ACCEL */
Temp = ACCEL_SendByte(ACCEL_DUMMY_BYTE);
/*!< Deselect the ACCEL: Chip Select high */
ACCEL_CS_HIGH();
return Temp;
}

This is a quick blind port, you'd need to configure the SPI pins, and the chip select pin (PA4) as a GPIO
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
james99maher
Associate II
Posted on November 24, 2016 at 00:29

Man, that's class. Thank you so much.

I'm just womdering why I need to send those bytes in that order. Is it not enough to input the register I'm looking for in order to get it back? Why is it not enough to put in 0x00, for example, to get DEVID_ID?

james99maher
Associate II
Posted on November 24, 2016 at 16:08

Actually, I should alter my question. I get that the first byte sent, 0x0B lets me read the register, then the second byte, 0x02, specifies what register to read. Why then do I need to send the dummy variable, 0xFF? 

Posted on November 24, 2016 at 16:36

The SPI traffic is symmetrical, you clock data in, data clocks out. After you have clocked the 0x02 into the chip, you have to clock the register content out.

The 0xFF is sent to generate the clocks. It could be any value.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..