Forum : ST7/STM8
Original Post
Post Information | Post |
---|---|
May 26, 2011 - 10:04am
|
Hi, I have been trying to add bit definitions for PA_ODR in STM8S105C_S.h. As it's written in ST7/STM8 C Compiler (*8 + ), I multiply base address (which in this case 0x5000) by 8 and add bit number (for PA_ODR.0, it's 0x28000). If I write exact address, it's ok: at 0x28000 hbit LATA0; If I write something like below, there won't be any warnings or errors but when I use that bit, it has no effect: at (((0x5000)*8)+0) hbit LATA0; Testing on simulator under Ride7 with the code below: #include "STM8S105C6.h" void main() Ride7 patch: v7.30.10.0169 |
Hi Quiss,
Thanks for your report. We have succesfully reproduced your issue.
The problem lies in the way you use the C preprocessor: "0x28000" is handled as a long value (remember we are on a 16-bit compiler). In the second form, "0x5000" is handled as an integer value (16-bit). When multiplied by 8, the binary operator identifies a multiplication of 2 16-bit values (0x5000 and 8) hence performs a 16-bit multiplication, which truncates the binary result "0x28000" and looses the upper part of the 16-bit value.
The solution is to qualify one of the operands of the multiplication as an unsigned long constant, and the result will be ok. This is a working solution:
Best Regards,
Hi Bruno,
It's working, thank you.