HCS08QG8 - IIC Read - Codewarrior Simulation

cancel
Showing results for 
Search instead for 
Did you mean: 

HCS08QG8 - IIC Read - Codewarrior Simulation

834 Views
Contributor III

Hello all,

 

I searched the 8 bit and 8 bit Codewarrior forums, but did find a similar post.

 

Currently, I am working on a test program to read al byte from the Microchip 23008 port expander.  No actual use of data, but only a test.  I have USB oscilloscope on order to see the IIC bus.  In the mean time, I am using the Codewarrior simulator to view the IIC bus transfer.  See the code below.  My question relates to the second byte received.  Is there actually a second byte received ?

 

Thanks

 

void DISPReadBarGraphData(void)
{
 
  unsigned char dout;
  unsigned char acknowledge;
 
  SEND_START_BIT;         // send start signal
  IICD = DISP_MCP_1_SL_ADDR;   // send MCP control byte (R\W bit preset to 0)
  while(!IICS_IICIF);     // wait for byte transfer to complete
  IICS_IICIF = 0;
  acknowledge = check_ACK();
  if (acknowledge == DEVICE_NO_ACK)
    return;
  IICD = DISP_OLAT;       // send MCP OLAT register address
  while(!IICS_IICIF);     // wait for byte transfer to complete
  IICS_IICIF = 0;
  acknowledge = check_ACK();
  if (acknowledge == DEVICE_NO_ACK)
    return;
  SEND_RPSTART_BIT;       // send repeat start bit
  IICD = DISP_MCP_1_SL_ADDR | 0x01;    // send MCP control byte (R\W bit set to 1        
  while(!IICS_IICIF); // wait for byte transfer to complete
  IICS_IICIF = 0;
  acknowledge = check_ACK();
  if (acknowledge == DEVICE_NO_ACK)
    return;
  IIC_RX_MODE;            // set IIC for recieve mode
  IICC_TXAK = 1;      // no ACK sent to slave
  dout = IICD;        // dummy read to clock byte in
  while(!IICS_IICIF); // wait for byte transfer to complete
  IICS_IICIF = 0;
  SEND_STOP_BIT;
  dout = IICD;
  DISPGraphContent = dout;
  }

Labels (1)
0 Kudos
1 Reply

21 Views
Contributor I

Hi,

 

I have not an answer to your question neither a solution but a similar problem.

 

My implementation looks equal:

 

void IIC_Init(void)
{
  // clear control and status register
  IIC1C = 0;
  IIC1S = 0;
 
  IIC1C_IICEN   = 1; // Enable I2C;
  IIC1C_TXAK    = 1; // not generate ACK by master after transfer;
  IIC1C_MST     = 1; // Master mode actually; Generates a start signal
  IIC1C_TX      = 1; // Master is transmitting
  IIC1F         = 0x40;   // mult = 1, ICR = 0; 
}

 

and my read looks like:

 

byte IIC_readFirst_byte(byte addr)
{
  byte temp;     
  temp = addr << 1;
 
  if(!IIC1C_MST)
    IIC1C_MST = 1;
 
  IIC1C_TXAK = 0; // RX/TX = 1; MS/SL = 1; TXAK = 0;
  IIC1C |= 0x30; // And generate START condition;
      
  IIC1D = temp; // Address the slave and set up for master transmit;

  while(!IIC1S_IICIF);     // wait for byte transfer to complete
  IIC1S_IICIF = 0;

  while(IIC1S_RXAK); // check for RXAK;
   //-----Slave ACK occurred------------
      IIC1C_RSTA = 1; // set up repeated start;
     
  IIC1D = 1; // read flag 1?
 
  while(!IIC1S_IICIF);     // wait for byte transfer to complete
  IIC1S_IICIF = 0;
    
   while (IIC1S_RXAK); // check for RXAK;
   //-----Slave ACK occurred------------
   IIC1C_TX = 0; // set up to receive;


   // dummy read
   RD_data = IIC1D;
 
   while(!IIC1S_IICIF);     // wait for byte transfer to complete
   IIC1S_IICIF = 0;
      
   IIC1C_TXAK = 0; // want to read more;

 

   return RD_data;
}

 

I do the reading then in an other function call because the data I want to receive

needs some time to be ready for transfer.

 

I do not get some "usable" data out of the I^2 bus and I do not know why.

 

I send the address of the slave out on the bus and afterwards I send the 1 for the

slave to write now, but I have found 2 astonishing surprises:

1. After I send the address of the slave the SDA line moves up after ack of the slave

has arrived! Is this normal???

 

2. When I do not do the step by step debugging I can see on the oszi that after

sending out the address of the slave, the restart routin is called and then not the 1

that I send afterwards is on the bus no, it is a 0xff! I have no glue where this comes from.

 

Do you know what is going on on the bus?

 

I do not really understand the information of the jpeg you have send with.

 

Maybe finding togehter a solution for both problems?

 

Greetings,

xmas

 

0 Kudos