Dear everyone,
I want to add new struct type called I2C_TypeDef to the CMSDK_CM3.h I followed the format, added right below the other CMSDK_TypeDef, but strangely the Keil IDE cannot recognize my new type. Here is what I added
/*------------------- I2C ----------------------------------------------*/ /** @addtogroup I2C @{ */ typedef struct { __IO uint32_t PRER; // <h> I2C Prescaler Register (R/W) </h> __IO uint32_t CTR; // <h> I2C Control Register (R/W) </h> __O uint32_t TXR; // <h> I2C Transmit Register (W) </h> __I uint32_t RXR; // <h> I2C Receive Register (R) </h> union { __O uint32_t CR; // <h> I2C Command Register (W) </h> __I uint32_t SR; // <h> I2C Status Register (R) </h> }; } I2C_TypeDef; /*@}*/ /* end of group I2C */
it is compiled but whenever I try to use the I2C_TypeDef in main, for example, I2C_TypeDef mySensor;
It doesn't compile with an 'error: unknown type name 'I2C_TypeDef' I am sure that I have included the CMSDK_CM3.h since the other CMSDK_xxx_typedef work just fine. Also, when I declare the struct in the same file as the main. It recognizes the struct and now compiles. Please, anybody know what is the problem? I am using Keil MDK5 by the way. Thank you for any help.
Possibility -
You have edited a CMSDK_CM3.h file and added the struct, but you have not edited the one that is actually included by your project.
I think I have included it right. But there is another strange things. Here it is.
I right-clicked on my typedef usage, click 'Go to definition of I2C_TypeDef', and browser couldn't find it.
However, I tried to change the I2C_TypeDef into CMSDK_I2C_TypeDef both in the CMSDK_CM3.h and the main. Then the browser found it on the CMSDK_CM3.h but the compiler warning still the same "unknown type CMSDK_I2C_TypeDef"
Any other idea?
Add a warning to the CMSDK_CM3.h file just before the typedef
#warning "My I2C Typedef Included"
When you compile, if this warning shows up before the error, you know it has been included properly. If it shows up after, you probably have a circular / recursive file include issue. If it does not show up at all, you are not including the file you have edited.
Knowing which of the 3 cases your issue falls into should point you in the right direction to be able to fix it.
Try naming the union
View all questions in Keil forum