IIC model can't work using MC9s08AW60,help,help!!!

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

IIC model can't work using MC9s08AW60,help,help!!!

296 Views
wenyabin
Contributor I

hello everyone,I'm still a chinese student,now I  use freescale's product MMa8451q using IIC comunication mode,so I choose MC9s08AW60's iic model to control it ,but it can't work rightly,hurting me.

so much word,I will give my code to let any friend point out potential mistake.

#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include "clock_delay.h"#include "sci.h"#define  turn_on_buzzer    PTADD_PTADD1=1;PTAD_PTAD1=1#define  shut_down_buzzer  PTAD_PTAD1=0#define  iic_start       IIC1C_MST=1#define  iic_stop        IIC1C_MST=0#define  iic_restart     IIC1C_RSTA=1#define  iic_acknowledge IIC1C_TXAK=0void iic_send(unsigned char data){        IIC1C|=0x30;     IIC1D=data;    while(!IIC1S_TCF);       /////////waiting for send complete            while(IIC1S_RXAK);       ///////////waiting for the ack from the slave    }unsigned char iic_read(void){       unsigned char temp;    IIC1C_TX=0;    temp=IIC1D;    while(!IIC1S_TCF);       /////////waiting for send complete    return(IIC1D);        }///////the mainvoid main(void) {  unsigned int i=10,n;  n=4;  clock_init();                        /////////////*seting 20Mhz bus clock;  sci_init();        //IIC1F=0b00011101;     ///////////////MULT=00, ICR=0x1d  IIC1F=0x1f;                ////////////////////*according to my calculating,this can get 1.65us sda hold time,but I can't sure if it's appropriate for mma8451q  //IIC1F=0x14;  IIC1C_IICEN=1;  IIC1C_IICIE=0;  IIC1C_TXAK=1;    EnableInterrupts; /* enable interrupts */  turn_on_buzzer;  delay_nms(100);  shut_down_buzzer;    while(1)  {     IIC1C_IICEN=1;     iic_send(0x38);     ///////////////    give the write commend     iic_send(0x0d);        /////////////////////provide the address of register     iic_restart;        ///////////////////////restart for reading     iic_send(0x39);             //////////////////give the read  commend     i=iic_read();     iic_stop;              IIC1C_IICEN=0;    /////////*if I don't clear this bit, this function can only circulate one circle,I don't know why,if I clear it,this while function can circulate,but I can only get i=0,meaning 8451q only return 0;This is another confusion!!!          five_digit_uart(i);       ///////*using sci to see it's value,the sci has no problem I promised     sci_send('\n');      turn_on_buzzer;     delay_nms(100);     shut_down_buzzer;          delay_nms(1000);                  } }

 now I do some illustrate:In my code , I use 20M bus clock;

 IIC1F=0x1f;                ////////////////////*according to my calculating,this can get 1.65us sda hold time,but I can't sure if it's appropriate for mma8451q
 IIC1C_IICEN=0;    /////////*if I don't clear this bit, this function can only circulate one circle,I don't know why,if I clear it,this while function can circulate,but I can only get i=0,meaning 8451q only return 0;This is another confusion!!!

waiting for help…………

Labels (1)
0 Kudos
0 Replies