6 years, 7 months ago.

Registers seen as Intergers

The mbed compiler seems to treat the LPC1768 registers as integers rather than unsigned uint32_t values. This makes testing bit 31 difficult. For example:

while((LPC_ADC->ADDR0 & (1 << 31)) == 0);

Gives a compiler warning, and also does not seem to work. Is there a way to have the registers treated as unsigned?

2 Answers

6 years, 7 months ago.

Hello John Harris,

please use casting. You either do (1U << 31) or ((uint32_t)1 << 31).


Accepted Answer
6 years, 7 months ago.

I happened to have the same issue with the KL25 yesterday.

A quick check just showed me it is correctly defined in the header files, so I made an advanced test program:

#include "mbed.h"

int main() {
    uint32_t testVar1; 
    testVar1 = (1<<31);

Also tried the same with unsigned int instead of uint32_t:

Warning: Integer operation result is out of range in "main.cpp", Line: 5, Col: 19
Warning: Integer conversion resulted in a change of sign in "main.cpp", Line: 5, Col: 15
Warning: Variable "testVar1" was set but never used in "main.cpp", Line: 4, Col: 13

With 30 it does fine, and also with uint16_t and uint8_t (and their correct length), so it is really that the length of an uint32_t is somewhere wrong in the compiler. Both with and without beta mode (don't know if there currently is a difference).

That said, the reason I only checked now and ignored it yesterday: it did work fine for me. Yeah it gave those warnings, but it set the registers correctly.