MC9S12XEP100 PORT口操作问题

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

MC9S12XEP100 PORT口操作问题

796 Views
cyesman
Contributor II

在用MC9S12XEP100,利用PIT产生1ms定时中断,定义一个“test_count”变量,在PIT中断服务函数中实现I/O翻转(PA6),用示波器观察,偶尔会出现PA6没有拉低或置1的现象,概率较高,用串口打印PORTA寄存器值,发现波形异常的时候,打印出来的值和波形对应上(比如正常输出是0xBF和0xFF间隔输出,波形异常的时候,连续出现3个0xBF或0xFF),说明等于20和24两个判断是进去了的,但是PORTA寄存器值修改没有成功。以下是程序示例:

换作其他I/O口问题现象相同。

test_count++;

if(test_count == 200)

{

     test_count = 0;

}

if(test_count == 20)

{

      PORTA &= ~(1 << 6);

      printf_flag = 1;

}

if(test_count == 24)

{

      PORTA |= 1 << 6;

      printf_flag = 1;

}

......

if(printf_flag == 1)

{

     printf_flag = 0;

     printf(PORTA);

}

0 Kudos
3 Replies

662 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

you have written to us on different communication channel: "Tks for your attention. Problem solved!"

Could you please share your solution with the world. Each resolved issue of one customer can be a help or solution to another one.

Moreover, we would like to ask you and appreciate if you communicate in English to all users connected to our community understand.

Best regards,

Ladislav

0 Kudos

662 Views
cyesman
Contributor II

1.png问题现象图片一2.png

问题现象图片二

0 Kudos

662 Views
kef2
Senior Contributor IV

Hi

1. Are you using XGATE? Are you writing to PORTA from XGATE? If both are true you are in trouble, you need to prevent simultaneous PORTA access from XGATE and CPU, semaphores may help. Of course it is better to not write access the same thing from both cores.

2. Since test_count increments each 1ms and you are comparing test_count against exact counter values (not less, not more but ==20, ==24 or ==200),  code snippet you provided should enter and execute more often than each 1ms. Do you have interrupts enabled? - interrupt latency should be much less than 1ms. Make sure as well printf() never takes 20-1 ms. 

Edward

0 Kudos