Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 1 month ago.
Reading registers from Nucleo
I found a lot of examples how to read registers from LPC17xx boards. In the file LPC17xx.h all pointers to the registers are listed (LPC_SC, LPC_I2C1 etc). But where can I found the same for the Nucleo board? The reason I want to read the registers is because the I2C function does not work on the Nucleo board with a program and an I2C-device which allways worked on my LPC1768 board. Any suggestions?
2 Answers
10 years, 1 month ago.
Here: http://mbed.org/users/mbed_official/code/mbed-src/file/0182c99221bc/targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx.h (see the folders in the url, they always use that structure, only the ST ones are filled with ST's own device driver library, so bit harder to find)
10 years, 1 month ago.
Accessing the url directly returns "Sorry, this page is currently unavailable." So I downloaded the whole repository. Now I am searching for the appropriate identifier to read the I2C registers. If I have success I let you know. Maybe you can give me a short example? Thank you.
Yeah the site seems to have some issues with some code currently, I also couldn't load it from a user repository, but when I went to the code via the API page it worked fine.
You did already find the file at targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx.h?
Relevant code parts (simply by searching for I2C):
typedef struct { __IO uint16_t CR1; /*!< I2C Control register 1, Address offset: 0x00 */ uint16_t RESERVED0; /*!< Reserved, 0x02 */ __IO uint16_t CR2; /*!< I2C Control register 2, Address offset: 0x04 */ uint16_t RESERVED1; /*!< Reserved, 0x06 */ __IO uint16_t OAR1; /*!< I2C Own address register 1, Address offset: 0x08 */ uint16_t RESERVED2; /*!< Reserved, 0x0A */ __IO uint16_t OAR2; /*!< I2C Own address register 2, Address offset: 0x0C */ uint16_t RESERVED3; /*!< Reserved, 0x0E */ __IO uint16_t DR; /*!< I2C Data register, Address offset: 0x10 */ uint16_t RESERVED4; /*!< Reserved, 0x12 */ __IO uint16_t SR1; /*!< I2C Status register 1, Address offset: 0x14 */ uint16_t RESERVED5; /*!< Reserved, 0x16 */ __IO uint16_t SR2; /*!< I2C Status register 2, Address offset: 0x18 */ uint16_t RESERVED6; /*!< Reserved, 0x1A */ __IO uint16_t CCR; /*!< I2C Clock control register, Address offset: 0x1C */ uint16_t RESERVED7; /*!< Reserved, 0x1E */ __IO uint16_t TRISE; /*!< I2C TRISE register, Address offset: 0x20 */ uint16_t RESERVED8; /*!< Reserved, 0x22 */ } I2C_TypeDef;
(From this we learn this peripheral was copy pasted from a 16-bit microcontroller, I guess they don't like changing something that works. One of the advantages of NXP microcontrollers, they have little of that legacy).
And:
#define I2C1 ((I2C_TypeDef *) I2C1_BASE) #define I2C2 ((I2C_TypeDef *) I2C2_BASE)
So apparantly they start counting at 1. Addressing a register should be something like:
I2C1->CR1 = 0xFF;