• AVR Freaks

Hot!Help using MCC generated I2C functions

Page: < 12 Showing page 2 of 2
Author
Mysil
Super Member
  • Total Posts : 3952
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: Help using MCC generated I2C functions 2020/10/28 11:13:46 (permalink)
0
Hi,
For Non-Interrupt configuration of the driver, the blocking loop is inside the i2c_master.c   file,
in function:  I2C_Poller()    and  I2C_MasterWaitForEvent(). 
 
For Interrupt configuration, you may make a copy of I2C_Master_Example.c,
or modify the generated file,  to comment out the blocking statement in all the functions you are using.
Then make your own code to call I2C_Close(); and check the returned value. Something like: 
    i2c_error_t  retVal;
            /* Check status of previously started operation. */
    {            /* For Interrupt driver, return with status. */
        retVal = I2C_Close();
        if (retVal == I2C_BUSY)        return retVal;    /* Transfer not yet completed, come back later. */
        if (retVal == I2C_NOERR)    return retVal;    /* Transfer complete, results available. */
        if (retVal == I2C_FAIL)                 /* Transfer Not successfull. */  
        return retVal;
    }   



You may see attached code for an example:
I may come back with a complete example program later.
 
    Mysil
 
#21
jgreenmt
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2020/10/19 12:11:40
  • Location: 0
  • Status: offline
Re: Help using MCC generated I2C functions 2020/10/30 07:37:05 (permalink)
0
Thank you Mysil. I will look forward to seeing your complete example. For now, I will start with what you have and if I make any progress I will post my code also.
#22
Mysil
Super Member
  • Total Posts : 3952
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: Help using MCC generated I2C functions 2020/11/06 11:47:41 (permalink)
0
Hi,
Attached here is modified version of Humidity sensor program.
It is still non-interrupt  blocking code.
Interrupt code will be coming at some later time.
 
There is a revised version of the Wakeup procedure, in a separate file.
It is changed to more closely follow specification in datasheet for the sensor.
Wakeup is now two steps with a 2 milliseecond wait between,
If your program have something else to do in that time, ...
For the Wakeup to function, code need to know what Port pins are used for MSSP signal lines.
There are two Custom Names specified in Pin Manager,  SDA for the SDA data signal, and SCL for SCL clock signal.
 
Could you test the program, and try to get a good Oscilloscope trace of SCL and SDA signals
with sampling rate of about 1 MHz or higher.  The wakeup sequence and data transfer is less than 20 milliseconds.
Then zoom in on  I2C address transfer if possible?
 
Regards,
    Mysil
 
 
 
#23
Mysil
Super Member
  • Total Posts : 3952
  • Reward points : 0
  • Joined: 2012/07/01 04:19:50
  • Location: Norway
  • Status: online
Re: Help using MCC generated I2C functions 2020/12/01 16:04:47 (permalink)
0
Hi Micah,

Have you made any progress in understanding how your instrument
Digilent Analog Discovery 2, work, and how it is used?

It may seem from capture in message #16 that observation is done with sampling frequency 400 kHz for 1 million samples.
This might capture a whole 2 seconds measurement sequence,
but sampling frequency may be too low to capture I2C signaling at 100 kHz.
And it is impossible to see any details in the signal, you may try to capture a shorter interval.

Also, capture in message #16 show a lot more signaling
than  should be from communication with the sensor.
Question is whether this is caused by noise on the signal lines,
other signaling on the same bus, or wrong setup for the instrument.
What are the signal voltage detection levels used by the Logic Analyzer Inputs?
Questions above are reason for me asking for observation of these signals using oscilloscope mode.

Signal decoding in the Logic Analyzer software seem to function,
but those error messages may indicate sampling frequency too low for the signaling rate,
or other settings not suitable for the actual signals.

Please be aware, that 'Blocking Communication' and 'Hanging program' are two different concepts, and should not be mixed up.

Blocking communication, means doing one thing at a time, and wait while message is transferred.
Waiting for 2 or 10 milliseconds, may not be a big deal if controlling mechanical equipment with time constants between 100 milliseconds and 10 seconds.

Non-blocking communication, is about ability to do other tasks while communication is ongoing.
While this may make your program able to respond sooner, it also make your program more complicated, and may be more vulnerable to bugs in your application code, or in MCC generated code.

I am trying to remove mistakes in the I2C code generated by MCC, and get Interrupt configuration of the I2C code to work better. I do this for my own curiosity, and possible benefit for other members. I am Not doing this on behalf of Microchip Company, but with a (small) hope that MCC developers may pay attention, and eventually improve the generated code.

If you are able to test in your environment, and provide feedback that is possible to interpret, it may be possible to get progress.
 
Attached are two experiment / example project packages.
The smaller one, Humidity_Sensor.zip  have only been run in simulator.
 
The other have configurations for 3 different devices, default configuration is with PIC16F1718.
In addition to wakeup code for the humidity sensor, it also have a scan for available devices on the bus,
and some Real-Time Clock stuff.
The I2C driver code in this project have some additional modifications.
There are UART print, using pin RC6 for TX data, with bitrate is 38400 bit/s.
 
Regards,
    Mysil
post edited by Mysil - 2020/12/01 16:21:33
#24
Page: < 12 Showing page 2 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5