Reply
Posts: 26
Registered: ‎07-26-2017
Accepted Solution

How to define SFRs as volatile

I've come to the conclusion that I need to define my SFRs as volatile as the Keil compiler isn't always bothering to do the reads and writes I need e.g.     SMB0CN0 |= SMB0CN0_MASTER__MASTER; doesn't write to SMB0CN0!

Can anyone suggest a good way of modifying the includes so that SI_SFR macro defines SFRs as volatile? I could edit si_toolchain.h but an update Simplicity Studio would probably revert my edit.

Posts: 3,150
Registered: ‎02-07-2002

Re: How to define SFRs as volatile

I don't know which device you're using but for e.g. the BusyBee SMB0CN0_MASTER__MASTER equals 0x80 and not 0x00. And since SMB0CN0_MASTER__MASTER is not a local variable the compiler cannot deduct that the result is never used. So this assignment should always take place, volatile or not.

 

Or is the assignment conditional and only takes place after SMB0CN0 has been read and found to have that bit set? Can you show the offending function code and possibly the generated asm as well?

Posts: 8,176
Registered: ‎08-13-2003

Re: How to define SFRs as volatile

methinks this is 'automatic"

 

there are many instances of e.g

while (TI == 0)

{

}

and they never failed

erik
Posts: 26
Registered: ‎07-26-2017

Re: How to define SFRs as volatile

Here's the disassembly from the debugger (just the last few lines of the C function). I have a disliking of assembler, so I'm no expert, but stepping through the problem is that the SMB0CN0 master bit isn't getting set.

 

133           SFRPAGE = 0;
00001633:   CLR     A
00001634:   MOV     0A7H, A
134           SMB0CN0 |= SMB0CN0_MASTER__MASTER;
00001636:   ORL     0C0H, #80H
135           eeWriteBusy = false;
00001639:   CLR     2H
136           tickers[TIdx_IIC].flag = false;
0000163b:   MOV     11H, A
137       }
0000163d:   RET

Posts: 3,150
Registered: ‎02-07-2002

Re: How to define SFRs as volatile

134           SMB0CN0 |= SMB0CN0_MASTER__MASTER;
00001636:   ORL     0C0H, #80H

 

So it does try to set the correct bit!

SMB0CN0 is at sfr address 0xC0 and ORL will 'or' directly into that address.

Is this sfr maybe in a different sfr page?

 

What device are you targeting?

Posts: 26
Registered: ‎07-26-2017

Re: How to define SFRs as volatile

OK, so you guys must be thinking I'm an idiot. I've brushed up on my assembler and I can see that the instruction does what it should. The problem is actually that the Master bit of SMB0CN0 is READ ONLY and reflects whether the peripheral is currently performing a transaction as bus master. Doh!

The target is an EFM8LB11F32.

Posts: 3,150
Registered: ‎02-07-2002

Re: How to define SFRs as volatile

Oliver,

 

I do not think you are an idiot.You just did not fully grasp what was going on. And if I had known the bit was readonly I would have said so.

 

Maarten

Posts: 26
Registered: ‎07-26-2017

Re: How to define SFRs as volatile

Thanks for the kind words. It's nice to have some positive comments rather than being put down.

Posts: 472
Registered: ‎01-18-2004

Re: How to define SFRs as volatile


OliverSedlacek wrote:

Thanks for the kind words. It's nice to have some positive comments rather than being put down.


We've all been there ... virtual beer going your way!