I2C Communication

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

I2C Communication

3,007 次查看
Pal
Contributor I
Hello All,
 
This is my first email in this forum.
 
I am using a Demonstration Board for Freescale MC9S08QG8. I am able to communicate with the PC (I made Visual C++ IIC Interface) using the IIC communication protocol. However, I can't understand one thing.
 
In the True Time Simulator & Real Time Debugger, when I press the (Green Arrow) i.e.Start/Continue (F5), I can communicate with the PC. However, when I am testing the stand alone  (ofcourse after having programmed the micontroller) - I am not able to communicate with the PC. I am using the parallel port of the computer.
 
Please let me know.
 
Sincerely,
 
Pal.
标签 (1)
0 项奖励
回复
5 回复数

918 次查看
japex92
Contributor I

Hello Pankaj, Paul and MAC,



I have been spending some days with a problem that I think it's the same Pankaj had. I am using MC9S08QG8 uC on my application, have to use a IIC and SCI interfaces, both works well (I think) on debbuging; but when I programmed as a standalone it does not seem  to be in the endless loop.

I have commented the WATCHDOG() line, and it only works on debbuing when transfering to a PC through a PC, I am using codewarrior 10.2;

Function: u8LM92ReadRegister(0x00), returns a zero when a reading is completed.

I did all you said; but it does not work!

#define Disable_COP() SOPT1 = 0x52;// Deshabilitar COP watchdog y habilitar BDM

#define PTB4_On() PTBD_PTBD4 = 1;

#define PTB4_Off()PTBD_PTBD4 = 0;

void SCI_ini(byte SCIC1_Config,byte SCIC2_Config,short SCIBD_Config);

void Send_Data(const unsigned char *Vec,byte TAM);

void Dummy_send(void);

extern float Temperatura;

float f;

const unsigned char tempo[2];

int i=0;

byte *pTx;

void main(void) {

  EnableInterrupts;

  /* include your code here */

  Disable_COP();

  /* Initialization registers */

  ICSTRM = *(unsigned char*far)0xFFAF; /* Initialize ICSTRM register from a non volatile memory */

  ICSC1 = 0x04; /* ICSC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=0,IREFSTEN=0 */

  ICSC2 = 0x00; /* ICSC2: BDIV=1,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */

  ICSSC = 00;  /* Initialize ICSSC register from a non volatile memory */

  PTBDD_PTBDD4 = 1;// set PTB4 as output

  init_I2C();

  SCI_ini(0x00,0x0C,0x1A);

  Dummy_send();


    

  for(;;) {

    //__RESET_WATCHDOG();/* feeds the dog */

  if(!u8LM92ReadRegister(0x00)) {
Temperatura;
if(Temperatura>30.00){
   PTB4_On();
}else{
      PTB4_Off();
}

  }

  } /* loop forever */

  /* please make sure that you never leave main */

}

0 项奖励
回复

918 次查看
paul
Contributor I
Are you using the COP ? If not you may need to disable it in the SOPT1 register. This should be done in your initialization area. You could also try to disable the BDM bit, also in the SOPT1 reg.
 
Maybe try a pin-toggling routine to see if your IIC code is running.
 
Something to be aware of, is that IIC uses open collector interface with  pullup resistors. I dont think your parallel port is open collector (open drain). You may need to use a pullup\diode arrangement to avoid data collision.
 
Hope this helps,
 
Paul
0 项奖励
回复

918 次查看
Pal
Contributor I
Thanks a lot Paul. It works now.

Another Question :

In the header file, one of the lines is as:

#define __RESET_WATCHDOG() {asm sta SRS;}

__RESET_WATCHDOG() function is called in a never ending "for" loop in the main function.

Can anyone let me know what is the meaning of {asm sta SRS} and significance of a never ending "for" loop.

Cheers.

Pankaj.
0 项奖励
回复

918 次查看
bigmac
Specialist III
Hello Pankaj,
 
The line containing
#define __RESET_WATCHDOG() {asm sta SRS;}
is a pre-processor macro that uses inline assembly code (defined by the asm part).  The assembly instruction sta SRS writes whatever value is in the accumulator, to the register identified by the label SRS.  This is the procedure necessary to reset the COP timer.
 
The never ending "for" loop is the main loop for the program.  Any code that is inside this loop will execute over and over, and this is the usual requirement for an embedded controller, where the operation of the program should never cease.  The reset of the COP timer is in this category.  Any code that preceeds the loop will be executed once only, and would normally include the initialisation processes required for the project.
 
Regards,
Mac
 
0 项奖励
回复

918 次查看
Pal
Contributor I
Thanks Mac.
0 项奖励
回复