• AVR Freaks

Hot!Update for MCC I2C driver

Author
cobusve
Super Member
  • Total Posts : 495
  • Reward points : 0
  • Joined: 2012/04/02 16:15:40
  • Location: Chandler
  • Status: offline
2019/11/03 11:47:40 (permalink)
5 (2)

Update for MCC I2C driver

I recently helped someone add a timeout on write to the MCC I2C driver. This was half-implemented in the MCC driver as is evident from the TODO comments in the code.
 
Can you guys take a look over here https://www.microforum.cc/topic/90-help-with-mcc-generated-i2csimple-getting-stuck-in-a-loop/ for the update.
 
I recommend you implement the timeout as I did in that post, and update the driver to return the -1 when the address has a NAK, also I would recommend you do not automatically enable the NAK polling as it is now, just remove that from the default, even leave it as a comment in case someone needs it.
 
I think getting a timeout when a slave device is not there is a pretty common use case that should be covered.

Also take a look at https://www.microforum.cc/ - a great resource for information on PIC and AVR microcontrollers and embedded programming in general. You can also post questions to the experts there.
#1

4 Replies Related Threads

    baileyb
    Junior Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2015/10/19 09:41:51
    • Location: 0
    • Status: offline
    Re: Update for MCC I2C driver 2019/11/08 11:11:54 (permalink)
    0
    This is good feedback. I will add it to the top of our list :)
    #2
    Mysil
    Super Member
    • Total Posts : 3403
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Update for MCC I2C driver 2019/11/09 04:16:40 (permalink)
    0
    Hi,
    Agreeing with cobusve in message #1,
    have looked into the thread in microforum,
    and are doing some experiments to reevaluate the Foundation Services I2C driver.
     
    Messages and suggestions in that thread mainly relate to device library version 1.77 and earlier,
    and Foundation Services library 1.34 and earlier.
     
    Uncritical use of retries in case of NACK in when a device not responding, or not connected,
    causing any program to hang, and jamming the bus for any other devices using the same lines,
    was a reason for me to discard the library entirely, a long time ago.
     
    As mentioned in the microforum thread, this default behaviour of SimpleMaster make it impossible to scan a bus to analyze what slave devices are available.
     
    There seem to be a new version of Foundation Services library have been released today,
    together with new version of PIC16... device library a few days ago,
    so I will hold any further criticism until I have studied what is in there.
     
        Mysil
    #3
    Mysil
    Super Member
    • Total Posts : 3403
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Update for MCC I2C driver 2019/11/10 04:55:05 (permalink)
    4 (1)
    Have experimented with a new project using MCC for use with I2C EEPROM memory devices
    pic10-pic12-pic16-pic18-1.78.0.jar  
    foundationServicesLibrary_v0.2.0.jar
    memoryProductsLibrary_v2.10.jar

    Description text in generated template main file is still not correct:
      Description:
        This header file provides implementations for driver APIs for all modules selected in the GUI.

    The main.c file is not a header file, and it provide nothing but a outline for a main source file.

    In device library v1.78   with memoryProducts 2.10 , some header files have been moved to different directory,
    and are not correctly located by EEPROM routines.

    It may seem that the foundationServices library may no longer be needed for this.
    In i2c_master_example.c   there are a number of API functions, similar to what is provided by i2c_simple_master.c
    The memory library provide it's own implementation using functions in i2c_master.c directly.

    It does however Not work out of the box:
    Some symbols have changed case,   
    EEPROM_driver.c  v3.0  referring to:
        i2c_restart_read  while i2c_master provide I2C_RESTART_READ
        i2c_continue   to      I2C_CONTINUE
            ...
    and function names:
        i2c_open       to      I2C_Open
        i2c_setDataCompleteCallback(...)  to  I2C_SetDataCompleteCallback
            ...
    note that      i2c_setAddressNACKCallback have changed to I2C_SetAddressNackCallback


    The Retry procedure used by EEPROM_driver, is not available any more
        I2C_SetAddressNackCallback((i2c_restartWrite,NULL); //NACK polling?  
    is not accepted.
    Maybe just as well, it probably never did work correctly,
    but instead of providing a solution, it push the problem back to application programmers.


    There will be more,
        Mysil
    #4
    Mysil
    Super Member
    • Total Posts : 3403
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Update for MCC I2C driver 2019/11/10 23:12:10 (permalink)
    0
    Memory Products library v2.10  do not correctly read data that was written.
     
    Or more precisely, it misplace data when writing past a page write buffer alignment boundary.
    Causing data in other locations in the same page to be overwritten.
     
    Here is output from a test program showing the problem:

     
    Example program using Microchip Code Configurator.
    By Mysil in Microchip Forum https://www.microchip.com/forums/FindPost/1118113
    Device library PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.78
    Memory Products library v2.10

    Write address 2048 values 55  FF  AA  CC  1  2  3  4 
    Read address 2048 values 55  FF  AA  CC  1  2  3  4
     

    Write address 2064 values 1032  1033  1034  1035  1036  1037  1038  1039
    Write address 2080 values 1040  1041  1042  1043  1044  1045  1046  1047
    Write address 2096 values 1048  1049  1050  1051  1052  1053  1054  1055
    Write address 2112 values 1056  1057  1058  1059  1060  1061  1062  1063
     
    Write address 2128 values 1064  1065  1066  1067  1068  1069  1070  1071
    Write address 2144 values 1072  1073  1074  1075  1076  1077  1078  1079
    Write address 2160 values 1080  1081  1082  1083  1084  1085  1086  1087
    Write address 2176 values 1088  1089  1090  1091  1092  1093  1094  1095
     
    Write address 2192 values 1096  1097  1098  1099  1100  1101  1102  1103
    Write address 2208 values 1104  1105  1106  1107  1108  1109  1110  1111
    Write address 2224 values 1112  1113  1114  1115  1116  1117  1118  1119
    Write address 2240 values 1120  1121  1122  1123  1124  1125  1126  1127
     
    Write address 2256 values 1128  1129  1130  1131  1132  1133  1134  1135
    Write address 2272 values 1136  1137  1138  1139  1140  1141  1142  1143
    Write address 2288 values 1144  1145  1146  1147  1148  1149  1150  1151
    Write address 2304 values 1152  1153  1154  1155  1156  1157  1158  1159
     
    Write address 2320 values 1160  1161  1162  1163  1164  1165  1166  1167
    Write address 2336 values 1168  1169  1170  1171  1172  1173  1174  1175
    Write address 2352 values 1176  1177  1178  1179  1180  1181  1182  1183
    Write address 2368 values 1184  1185  1186  1187  1188  1189  1190  1191
     
    Write address 2384 values 1192  1193  1194  1195  1196  1197  1198  1199
    Write address 2400 values 1200  1201  1202  1203  1204  1205  1206  1207
    Write address 2416 values 1208  1209  1210  1211  1212  1213  1214  1215
    Write address 2432 values 1216  1217  1218  1219  1220  1221  1222  1223
     
    Write address 2448 values 1224  1225  1226  1227  1228  1229  1230  1231
    Write address 2464 values 1232  1233  1234  1235  1236  1237  1238  1239
    Write address 2480 values 1240  1241  1242  1243  1244  1245  1246  1247
    Write address 2496 values 1248  1249  1250  1251  1252  1253  1254  1255
     
    Write address 2512 values 1256  1257  1258  1259  1260  1261  1262  1263
    Write address 2528 values 1264  1265  1266  1267  1268  1269  1270  1271
    Write address 2544 values 1272  1273  1274  1275  1276  1277  1278  1279
    Write address 2560 values 1280  1281  1282  1283  1284  1285  1286  1287
     
    Read address 2048 values 1088  1089  1090  1091  1092  1093  1094  1095
     
    Read address 2064 values 1032  1033  1034  1035  1036  1037  1038  1039
    Read address 2080 values 1040  1041  1042  1043  1044  1045  1046  1047
    Read address 2096 values 1048  1049  1050  1051  1052  1053  1054  1055
    Read address 2112 values 1056  1057  1058  1059  1060  1061  1062  1063
     
     
    Read address 2128 values 1064  1065  1066  1067  1068  1069  1070  1071
    Read address 2144 values 1072  1073  1074  1075  1076  1077  1078  1079
    Read address 2160 values 1080  1081  1082  1083  1084  1085  1086  1087
    Read address 2176 values 1152  1153  1154  1155  1156  1157  1158  1159
     
    Test difference, read result 1152  write value 1088  index 24
    Test difference, read result 1153  write value 1089  index 25
    Test difference, read result 1154  write value 1090  index 26
    Test difference, read result 1155  write value 1091  index 27
    Test difference, read result 1156  write value 1092  index 28
    Test difference, read result 1157  write value 1093  index 29
    Test difference, read result 1158  write value 1094  index 30
    Test difference, read result 1159  write value 1095  index 31
     
    Read address 2192 values 1096  1097  1098  1099  1100  1101  1102  1103
    Read address 2208 values 1104  1105  1106  1107  1108  1109  1110  1111
    Read address 2224 values 1112  1113  1114  1115  1116  1117  1118  1119
    Read address 2240 values 1120  1121  1122  1123  1124  1125  1126  1127
     
     
    Read address 2256 values 1128  1129  1130  1131  1132  1133  1134  1135
    Read address 2272 values 1136  1137  1138  1139  1140  1141  1142  1143
    Read address 2288 values 1144  1145  1146  1147  1148  1149  1150  1151
    Read address 2304 values 1216  1217  1218  1219  1220  1221  1222  1223
     
    Test difference, read result 1216  write value 1152  index 24
    Test difference, read result 1217  write value 1153  index 25
    Test difference, read result 1218  write value 1154  index 26
    Test difference, read result 1219  write value 1155  index 27
    Test difference, read result 1220  write value 1156  index 28
    Test difference, read result 1221  write value 1157  index 29
    Test difference, read result 1222  write value 1158  index 30
    Test difference, read result 1223  write value 1159  index 31
     
    Read address 2320 values 1160  1161  1162  1163  1164  1165  1166  1167
    Read address 2336 values 1168  1169  1170  1171  1172  1173  1174  1175
    Read address 2352 values 1176  1177  1178  1179  1180  1181  1182  1183
    Read address 2368 values 1184  1185  1186  1187  1188  1189  1190  1191
     
     
    Read address 2384 values 1192  1193  1194  1195  1196  1197  1198  1199
    Read address 2400 values 1200  1201  1202  1203  1204  1205  1206  1207
    Read address 2416 values 1208  1209  1210  1211  1212  1213  1214  1215
    Read address 2432 values 1280  1281  1282  1283  1284  1285  1286  1287
     
    Test difference, read result 1280  write value 1216  index 24
    Test difference, read result 1281  write value 1217  index 25
    Test difference, read result 1282  write value 1218  index 26
    Test difference, read result 1283  write value 1219  index 27
    Test difference, read result 1284  write value 1220  index 28
    Test difference, read result 1285  write value 1221  index 29
    Test difference, read result 1286  write value 1222  index 30
    Test difference, read result 1287  write value 1223  index 31
     
    Read address 2448 values 1224  1225  1226  1227  1228  1229  1230  1231
    Read address 2464 values 1232  1233  1234  1235  1236  1237  1238  1239
    Read address 2480 values 1240  1241  1242  1243  1244  1245  1246  1247
    Read address 2496 values 1248  1249  1250  1251  1252  1253  1254  1255
     
     
    Read address 2512 values 1256  1257  1258  1259  1260  1261  1262  1263
    Read address 2528 values 1264  1265  1266  1267  1268  1269  1270  1271
    Read address 2544 values 1272  1273  1274  1275  1276  1277  1278  1279
    Read address 2560 values 65535  65535  65535  65535  65535  65535  65535  65535
     
    Test difference, read result 65535  write value 1280  index 24
    Test difference, read result 65535  write value 1281  index 25
    Test difference, read result 65535  write value 1282  index 26
    Test difference, read result 65535  write value 1283  index 27
    Test difference, read result 65535  write value 1284  index 28
    Test difference, read result 65535  write value 1285  index 29
    Test difference, read result 65535  write value 1286  index 30
    Test difference, read result 65535  write value 1287  index 31
     
    Test completed with errors.

     
    Test program have been created with MCC plugin version 3.85.1 with core 4.75
    Device library PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.78
    Memory Products library v2.10
     
    MPLAB X IDE v5.25 running on PC with Windows 7 PRO
    using XC8 compiler v2.10 in C99 mode with C99 libraries.
     
    For a PIC16F1619 in 20 pin PDIP on a Curiosity board,
    with I2C connections to  24LC512  EEPROM with all 3 Address pins pulled high.
    EEPROM is addressed with 7 bit I2C address 0x57. 
    There is reporting to UART TX on pin RB7, at 38400 bit/s, 8 bits, no parity.
     
    Program should be possible to port to most similar PIC16F1xxx devices,
    by configuring with MCC, or manually.
     
    MPLAB X project package is attached.
    There are some more notes in file EEPROM_notater.txt  inside the .zip file.
    There is also a copy of the Testdump.txt file inside the .zip.
     
    Regards,
        Mysil
    post edited by Mysil - 2019/11/10 23:55:09
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5