I2C between HCS08AW60 and Arduino

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

I2C between HCS08AW60 and Arduino

2,162 Views
gregorypiaskowy
Contributor I

Dear NXP community I am trying to connect Arduino UNO (Atmega 328p) as a master with a slave S08AW60.

I found a paper from 2007 where there is a presentation of I2C to that family I have followed instructions but still I have SDA and SCL constantly high.

And Arduino master doesn't read anything.

 

Anyone have tried to connect these 2 MCUs maybe? Or have any clues.

 

Thank you all very much.

 

Gregory

Labels (1)
0 Kudos
Reply
10 Replies

1,785 Views
Stano
NXP Employee
NXP Employee

I think you have not properly initialized the I2C module. For this MCU you can use the same set-up as for S08GB60 "oldMCU". The basic set-up is mentioned in the AN3291:

http://cache.nxp.com/files/microcontrollers/doc/app_note/AN3291.pdf?fsrch=1&sr=1&pageNum=1

When you check the communication by the scope, the SCL and SDA pins must be default in log1 with pulses to log0 while communicate. All details are in this AN.

I hope this helps you.

Best Regards,

Stano.

0 Kudos
Reply

1,785 Views
gregorypiaskowy
Contributor I

Thank you for your answer Stano!

I tried to follow the data sheet which is provided to AW60 MCU and the paper you have provided. I tried to make communications between 2 freescale MCUs and it seems to send address and then it stuck. Could you please see my code and give me some tips to it.

Thank you very much

Gregory

for slave I have

void Setup(){

IIC1A = 0x20; 

IIC1C_IICEN = 1;

IIC1C_IICIE = 0;

IIC1C_MST = 0;

IIC1C_TX = 0;

IIC1C_TXAK =0;

IIC1C_RSTA = 0;

     

}

and function for slave to get data from master

IIC1C_TX = 0;

  IIC1C_MST = 0;

   

  PTFD =IIC1S;

  while(IIC1S_ARBL ==1);

 

   Delay(1);

  while(IIC1S_IAAS == 0);

  if (IIC1S_SRW==0){

 

      IIC1C_TX = 0;

      u = IIC1D;

  }

  Delay(10);

 

  while(IIC1S_IAAS==1);

 

  while(IIC1S_TCF==1);

 

  data = IIC1D;

 

   

for master MCU

void I2C_setup() {

 

IIC1C_IICEN = 1;

IIC1C_IICIE = 0;

IIC1C_MST = 0;

IIC1C_TX = 0;

IIC1C_TXAK =0;

IIC1C_RSTA = 0;

IIC1F = 0x22;

IIC1A = 0x20; 

}

and to send data to slave MCU

      IIC1C_TX = 1;

    

      IIC1C_MST=1;

     

     

      Delay(10);

   

      IIC1D=0x20;//00100000

     

      while(IIC1S_RXAK==1){

         

      }

      IIC1C_TX = 0;

      temp=IIC1D;

     

      IIC1C_TX = 1;

     

      while(IIC1S_TCF==0);

      IIC1D=0x10;

     

    IIC1C_TX = 0;

      IIC1C_MST=0;

0 Kudos
Reply

1,785 Views
Stano
NXP Employee
NXP Employee

Hi Gregory,

first of all you need make decision which of both will be the Master and then second one will be the Slave. The I2C communication is always controlled by Master. Master can initialize communication, it can write or read from Slave. If the Slave want to send such information to master, it could be presented as such common interrupt ("non-I2c" - e.g. GPIO generated event by Slave). This is one possible way how to tell Master that Slave has new info. Then Master musts ask Slave to provide new data, thus Master musts process the Read function. The next option is periodically process Read function by Master to ask Slave for new info. The first option is better, because the communication channel is used effectively.

In case the AW60 will be the Master and Arduino the Slave, you can use the code from the attached example for master side. There are basic instruction only, excluding the error messages processing.

Please check this example and compare with your code. You need have properly running the I2C code on the Slave as first. The best way how to debug your project is to use the standard I2C EEPROM as the first "Test_Slave". Then build and debug the Master side. As the second phase you can build the Slave side (on Arduino), because the Master is running properly.

I hope it could help you.

Best Regards,

Stano.

1,785 Views
gregorypiaskowy
Contributor I

Thank you Stano!

I will follow your instructions and hopefully MCUs will start properly talking.

Kind regards:

Gregory

0 Kudos
Reply

1,785 Views
Stano
NXP Employee
NXP Employee

OK, Gregory,

let me know the results.

Best Regards,

Stano.

0 Kudos
Reply

1,785 Views
gregorypiaskowy
Contributor I

Hi Stano!

I have managed to program 2 identical AW60 MCUs and I have some data send, however, I have to do it manually, it looks that program gets stuck. I need to "send" the slave address manually and then program does the rest. I was following yours instruction from the paper and using the data sheet for MCU. I don't have any idea why it is not working now. Could you please see my codes for master and slave and give me some feedback ?

Thank you :smileyhappy:

Kind Regards:

Gregory

0 Kudos
Reply

1,784 Views
Stano
NXP Employee
NXP Employee

Hi Gregory,

I have checked your code.

Here is the first reason for the code not runs properly:

The IIC module on the RX site can held the bus in "Busy" state after power-ON event. So the best way is first to check the bus state. Here is the example which I have used for this task:

void Test_IIC_Bus(void)

{

   if((IIC1S_BUSY) || (IIC1S_ARBL)) WaitNms(5);

   if((IIC1S_BUSY) || (IIC1S_ARBL)) WaitNms(5);

   if((IIC1S_BUSY) || (IIC1S_ARBL)) WaitNms(5);

   if((IIC1S_BUSY) || (IIC1S_ARBL)) Reset_IIC();

}

When the bus is "locked" in the busy state by slave device, it has to be used the "IIC Reset" function. See example:

void Reset_IIC(void)

{

   IIC1C_IICEN = 0;    // Disable IIC;

   SCL = 1;

   Wait_sh(10);

   SDA = 0;

   Wait_sh(10);

   for(i=0;i<9;i++)

   {

     SCL = 1;

     Wait_sh(10);

     SCL = 0;

     Wait_sh(10);

   }

   SCL = 1;

   Wait_sh(10);

   SDA = 1;

   IIC1C_IICEN = 1;    // Enable IIC;

   Wait_sh(20);

}

This routine sends START bit, 9 SCL clocks with no data (SDA = 0) and then STOP bit. This sequence resets all connected slaves on the IIC bus. Then the bus is ready to use.

The second reason:

The MST bit has to be cleared in the IIC_Init() function. When the MST goes from 0 to 1 it bit generates the START condition on IIC bus. Then the slave expects the SCL clocks with such address and R/W command on SDA line.

So please make corrections in your code in accordance to my examples. As the first step use such simple Slave device (e.g. IIC EEPROM) to debug the master side of your code. The good guide could be the AN3291 also. You can use copy/paste for that code example, because IIC modules are the same in GB60 and AW60 MCUs.

I hope it can help you, but send me please the message with result.

Best Regards,

Stano.

0 Kudos
Reply

1,785 Views
gregorypiaskowy
Contributor I

Hi Stano!

Thank you very much for your answer. I will modify my code using your instructions :smileyhappy: and hopefully it will work.

Kind Regards:

Gregory

0 Kudos
Reply

1,785 Views
vicentegomez
NXP TechSupport
NXP TechSupport

Hi Gregory,

the SCL and SDA are open- drain output,because of this you need to add pull up resistor on those lines.

I hope this will help you.

Regards

Vicente Gomez

0 Kudos
Reply

1,785 Views
gregorypiaskowy
Contributor I

Hi Vincente

Thank you for yours answer, I know there are 2 4,7k pull up resistors for these lines. Now the freescale S08AW60 is master MCU and Arduino is a slave but it seems that slave doesn't add its bit. I have control byte address one and data but Arduino doesn't get any values when looking at SDA line on oscilloscope.

Thank you :smileyhappy:

Gregory

0 Kudos
Reply