Writing into register

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hello forum!

I hopefully have a simple question.
For example i want to write into register SCTR and field TRM. I do this with "USIC0_CH1->SCTR |= (1<<8);" But when i look at the register with the debugger the value in the register haven't change. Most of the register have the value 0xFFFFFFFF.
Where is my error in reasoning?

MfG z3t
0 Likes
8 Replies
User13817
Level 3
Level 3
Hello,

I use the following macro which is the same thing that you are doing:

#define setBit(reg, pos) (reg |= ((uint32_t)1<
Probably this register is read only or it has some mask, did you check that?
0 Likes
Not applicable
Hi Persike,

the register is not read only. I dont get it. It should work.
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi z3t,

from this sentence "Most of the register have the value 0xFFFFFFFF", I guess you haven´t enabled USIC module...so try first to initialize it. Reset value of SCTR register is 0x0000 0000. So I guess once you reach that state you can try setting the bitfield value as you tried above.

Best regards,
Deni
0 Likes
Not applicable
Hi Deni,
i can not enable USIC module, because i can not write into CCR. I have the same problem here. I have a couple of xmc1100s so i can exclude a damaged chip. Something else to try?

Best regards,
z3t
0 Likes
User13817
Level 3
Level 3
z3t wrote:
Hi Deni,
i can not enable USIC module, because i can not write into CCR. I have the same problem here. I have a couple of xmc1100s so i can exclude a damaged chip. Something else to try?

Best regards,
z3t


Hello z3t,

Try to init the module using the Dave APP and then you will be able to write on the desired register. Probably you're missing some initialization, let Dave work for you 😄
0 Likes
Not applicable
Hi Persike, i tried it with DAVE Apps. Now the register former written with 0xFFFFFFFF are now written with 0x00000000, but i still can not write into the register. (I don't want to use DAVE Apps, i need to do it the "hard way". 😉
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi z3t,

so if the DAVE is not what you want try something like this...I hope this is the "hard way" that you were referring to 😉


#include "XMC1100.h"

// UART baud rate constants for 57.8kbps @ MCLK=8MHz
#define FDR_STEP 590UL
#define BRG_PDIV 4UL
#define BRG_DCTQ 15UL
#define BRG_PCTQ 0UL

int main(void)
{
// Clock configuration
SCU_GENERAL->PASSWD = 0x000000C0UL; // disable bit protection
SCU_CLK->CLKCR = 0x3FF00400UL; // MCLK = 8MHz, PCLK = 8MHz
while((SCU_CLK->CLKCR & SCU_CLK_CLKCR_VDDC2LOW_Msk));
SCU_GENERAL->PASSWD = 0x000000C3UL; // enable bit protection
SystemCoreClockUpdate();

// Disable clock gating to USIC0
SCU_GENERAL->PASSWD = 0x000000C0UL; // disable bit protection
SCU_CLK->CGATCLR0 |= SCU_CLK_CGATCLR0_USIC0_Msk;
SCU_GENERAL->PASSWD = 0x000000C3UL; // enable bit protection

/* Enable the module kernel clock and the module functionality */
USIC0_CH1->KSCFG |= USIC_CH_KSCFG_MODEN_Msk | USIC_CH_KSCFG_BPMODEN_Msk;

/* fFD = fPB */
/* FDR.DM = 02b (Fractional divider mode) */
USIC0_CH1->FDR &= ~(USIC_CH_FDR_DM_Msk | USIC_CH_FDR_STEP_Msk);
USIC0_CH1->FDR |= (0x02UL << USIC_CH_FDR_DM_Pos) | (FDR_STEP << USIC_CH_FDR_STEP_Pos);

/* Configure baud rate generator */
/* BAUDRATE = fCTQIN/(BRG.PCTQ x BRG.DCTQ) */
/* CLKSEL = 0 (fPIN = fFD), CTQSEL = 00b (fCTQIN = fPDIV), PPPEN = 0 (fPPP=fPIN) */
USIC0_CH0->BRG &= ~(USIC_CH_BRG_PCTQ_Msk | USIC_CH_BRG_DCTQ_Msk | USIC_CH_BRG_PDIV_Msk | USIC_CH_BRG_CLKSEL_Msk | USIC_CH_BRG_PPPEN_Msk);
USIC0_CH1->BRG |= (BRG_PCTQ << USIC_CH_BRG_PCTQ_Pos) | (BRG_DCTQ << USIC_CH_BRG_DCTQ_Pos) | (BRG_PDIV << USIC_CH_BRG_PDIV_Pos);

/* Configuration of USIC Shift Control */
/* SCTR.FLE = 8 (Frame Length) */
/* SCTR.WLE = 8 (Word Length) */
/* SCTR.TRM = 1 (Transmission Mode) */
/* SCTR.PDL = 1 (This bit defines the output level at the shift data output signal when no data is available for transmission) */
USIC0_CH1->SCTR &= ~(USIC_CH_SCTR_TRM_Msk | USIC_CH_SCTR_FLE_Msk | USIC_CH_SCTR_WLE_Msk);
USIC0_CH1->SCTR |= USIC_CH_SCTR_PDL_Msk | (0x01UL << USIC_CH_SCTR_TRM_Pos) | (0x07UL << USIC_CH_SCTR_FLE_Pos) | (0x07UL << USIC_CH_SCTR_WLE_Pos);

while(1);
}


Set breakpoint at "while" loop and verify that you see the value "1" at SCTR.TRM bitfield. It should be there and then you can see what is necessary to do before writing to the register. I guess the most important lines are " // Disable clock gating to USIC0" and " /* Enable the module kernel clock and the module functionality */ ". You should check if the setting up baudrate is really necessary to be performed before setting TRM bitfield.

P.S This code I took from a EasyMain project that is generated once you select "File" -> "New Project" -> "DAVE project". Then select "Easy Start Project" and your microcontroller and you´re set to try it out by yourself. Should be helpful to see how UART is initialized old school way :cool:

Best regards,
Deni
0 Likes
Not applicable
Hi DRubesa,

you are right! The "Disable clock gating to USIC0"-Block and the "Enable the module kernel clock and the module functionality" are instruction-sets which opened the opportunity to write into those register. Thank you!
0 Likes