Failed to write SCI register

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Failed to write SCI register

1,410件の閲覧回数
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 件の賞賛
返信
2 返答(返信)

1,209件の閲覧回数
kef2
Senior Contributor V

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

1,209件の閲覧回数
jeffcharles
Contributor III

Hello Edward,

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

Thanks!

0 件の賞賛
返信