Failed to write SCI register

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Failed to write SCI register

542 Views
jeffcharles
Contributor III

Hi, I'm configuring the register of SCI about MC9S12G128 now. For easy to call the function of SCI0, SCI1 and SCI2, I declare a SCIx_TypeDef type of structure whose member variables are mapped with registers.

/* SCIx register base address */
#define SCI0 ((SCIx_TypeDef*)(0x000000C8UL))
#define SCI1 ((SCIx_TypeDef*)(0x000000D0UL))
#define SCI2 ((SCIx_TypeDef*)(0x000000E8UL))

typedef struct
{
volatile SCIBDSTR _BD;
volatile SCIACR2STR _ACR2;
volatile SCICR2STR _CR2;
volatile SCISR1STR _SR1;
volatile SCISR2STR _SR2;
volatile SCIDRHSTR _DRH;
volatile SCIDRLSTR _DRL;
}SCIx_TypeDef;

New a header file named SCI.h that is in the attachment, redeclare registers map that can be shared by SCI0, SCI1 and SCI2.

Then I write three functions for the test and the debug result is shown in an attachment.

void SCI_IrDAconfig_1(SCIx_TypeDef* SCIx)
{
SCIx->BD_IREN = 1;

SCIx->BD_TNP0 = 1;
SCIx->BD_TNP1 = 1;
}
void SCI_IrDAconfig_2(SCIx_TypeDef* SCIx)
{
SCIx->BD_IREN = 1;

SCIx->BD_TNP = 0x3;
}
void SCI_IrDAconfig_3(SCIx_TypeDef* SCIx)
{
SCIx->BD = 0xe000;
}

It seems that write a word(16-bit) or 2-bit operation is successful but write 1-bit operation is failed.
Why is that? Please give me some support. Many thanks!

0 Kudos
2 Replies

341 Views
kef2
Senior Contributor IV

Hi,

Structs and bitfields are not portable. It seems you like them so much, OK, but you forgot to copy paste few important lines from mc9s12g128.h:

at top:

#pragma OPTION ADD V30toV31Compatible "-BfaGapLimitBits4294967295" /*this guarantee correct bitfield positions*/

at bottom:

#ifndef __V30COMPATIBLE__
#pragma OPTION DEL V30toV31Compatible
#endif

Could you please add these to your sci.h and check if it helps?

Edward

341 Views
jeffcharles
Contributor III

Hello Edward,

I tried to add them to my sci.h and the debug result accords with the expectation.

Thanks!

0 Kudos