Initializing MAX11068 with MC9S12DG256CFU - Processor Expert - I2C Bean

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

Initializing MAX11068 with MC9S12DG256CFU - Processor Expert - I2C Bean

834 次查看
chill23
Contributor I

I am using Codewarrior version 5.9.0 and Processor Expert Version 3.02 to program an MC9S12DG256CFU to control the MAX11068 battery monitoring chip.  I have never used I2C before and I have limited experience working with these microcontrollers. 

 

I would like to use the I2C functions provided by the processer expert bean, but I am having trouble intializing the MAX11068.  I assume the connections are correct because the I2C functions are returning 0x00 for there error code.  Page 58 of the MAX11068 outlines the two initialization sequences I am working on called "HELLOALL" and "ROLLCALL". 

 

Issues:

 

1. With the HELLOALL command all I need to do is send one byte on the data line for the devices to start assigning themselves addresses.  Here is the basic code I am using:

 

    helloByte=0xE0;   //This is the command Byte that assigns the first device address
    error[0] = EI2C1_SelectSlave(helloByte);  //There is no slave address yet, so assigning command byte.
    error[0] = EI2C1_SendChar(0x00);

    error[0] = EI2C1_SendStop();


I received an acknowledge, but I am not sure this code is working because I send that zero byte.  Is there any way to just send the command byte?

 

2. With the ROLLCALL command I need to be able to perform a restart to change the master from transmitting to receiving..  There doesn't seem to be anyway of doing this, so I have been trying to just set the RSTA bit of the IBCR register myself. 

 

    error[0]=EI2C1_SelectSlave(BRDADDRW); //Broadcast set to write
    error[0]=EI2C1_SendChar(0x01);       //Command For Device Address Register
    IBCR &= ~0x0C;   //~00001100 = 11110011 //Set Restart and Auto Ack
   error[0]=EI2C1_RecvBlock(all_addresses,2,rec);  //I only have one device connected so only 2 bytes should be received

 

Is there anyway to perform a restart with the Processor Expert functions?  Other than setting the restart bit should I be setting any other bits or will the Bean functions handle the rest?     

 

Thanks

标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

549 次查看
ProcessorExpert
Senior Contributor III

Hello,

 

1 - There is no capablity to send only command byte in the InternalI2C component.

2 - Restart is performed within "RecvBlock" method in case "Automatic stop condition" is set to "no". For more details please see the code of this method:

 

  if(IBCR_MS_SL) {                     /* Is device in master mode? */
    IBCR_RSTA = 1U;                    /* If yes then repeat start cycle generated */
  }

 

best regards
Vojtech Filip
Processor Expert Support Team

0 项奖励
回复

549 次查看
chill23
Contributor I

I have viewed the processor expert code, but it does not use the defined registers.  It simply accesses the data and clock pins directly.  Also, I have determined I won't be able to use the receive command because I need to be able to send the address of the slave and then send the address of the register I want to read.

 

So with that determined, I wrote code using the methods outlined in AN3291.pdf.   In my configuration the microcontroller will always be the master.  The code seems to be working and I can read and write from the device some of the time.  The problem is that the microcontroller loses arbitration most of the time and the program hangs in either a loop looking for the interrupt flag or a loop waiting for the RXAK bit to be set. 

 

I think there are two problems occuring, one: the bus frequency isn't optimal and two: on-reset of the microcontroller the bus is hanging.

 

1. Can someone explain to me which i2c values listed on page 5 of the Maxim11068 datasheet correspond to the table  in the S12IICV2.pdf?  The internal bus clock of the microcontroller is set to 24MHz and the max speed of the MAXIM chip is 200kHz. so I know I need a divider of 120 or greater.  I am not sure how to compare the other values.

 

Again, all of my code is written according to the an3291.pdf polling method.

 

 

 

0 项奖励
回复