ADcmXL3021: Sensor crashes after alarm edit & measurement

Hey,

My ADcmXL3021 sensor (firmware version 2.6) seems to crash after saving alarm registers to flash and triggering a measurement afterwards. The crash happens non-deterministically, sometimes I can go close to 50 iterations of my program loop without crashing while at other times it crashes before 10. I was wondering if this might be a problem with my program logic or the sensor itself? My program flow goes as follows

// main loop

Set bit 11 of GLOB_CMD (measure)

// alarm band loop

Set alarm band number to ALM_PNTR (1 - 6)

Set bit 14 of GLOB_CMD (load alarm registers from flash)

Set ALM_F_LOW and ALM_F_HIGH (no overlap between the bins of different bands)

Set ALM_MAG1 and ALM_MAG2 for each axis

Set bit 12 of GLOB_CMD (save alarm registers to flash)

// end alarm band loop

//end main loop

Any ideas would be highly appreciated. Also, sorry for accidentally deleting the earlier version of this question.

  • I found a specific sequence that crashes the sensor every time I run it. I will attach a log file of reg dump + me running this sequence.

    It goes as follows:

    1) Clear bits 0, 1 and 2 in ALM_CTRL (because i believe alarms getting triggered might be a separate crash source)

    2) Set bit 9 in GLOB_CMD (clear alarm band registers from FLASH memory)

    3) Set ALM_PNTR to 4 (any band apart from 1 should work)

    4) Set ALM_F_LOW = 100 and ALM_F_HIGH = 200 (meaningless test values)

    5) Set ALM_X_MAG1 = 1 and ALM_X_MAG2 = 2 (meaningless test values)

    6) Set bit 12 of GLOB_CMD (save alarm band registers to FLASH memory)

    7) Set ALM_X_MAG1 = 10 and ALM_X_MAG2 = 20 (any value bigger than the earlier saved value works)

    8) Set bit 12 of GLOB_CMD (save alarm band registers to FLASH memory)

    9) Set bit 14 in GLOB_CMD (load alarm band registers from FLASH memory)

    10) Congratulations, your sensor should have crashed now!

    regdump and crash.txt
    =~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2020.01.27 15:29:54 =~=~=~=~=~=~=~=~=~=~=~=
    
    acc_regdump
    
    -- regdump --
    SPI write: 0x0
    SPI read: 0x0
    reg 0: 0
    SPI write: 0x200
    SPI read: 0x3bd
    reg 2: 3bd
    SPI write: 0x400
    SPI read: 0x401
    reg 4: 401
    SPI write: 0x600
    SPI read: 0x8
    reg 6: 8
    SPI write: 0x800
    SPI read: 0x101
    reg 8: 101
    SPI write: 0xa00
    SPI read: 0x0
    reg a: 0
    SPI write: 0xc00
    SPI read: 0x0
    reg c: 0
    SPI write: 0xe00
    SPI read: 0x0
    reg e: 0
    SPI write: 0x1000
    SPI read: 0x0
    reg 10: 0
    SPI write: 0x1200
    SPI read: 0x0
    reg 12: 0
    SPI write: 0x1400
    SPI read: 0x0
    reg 14: 0
    SPI write: 0x1600
    SPI read: 0x0
    reg 16: 0
    SPI write: 0x1800
    SPI read: 0x0
    reg 18: 0
    SPI write: 0x1a00
    SPI read: 0x1100
    reg 1a: 1100
    SPI write: 0x1c00
    SPI read: 0xff
    reg 1c: ff
    SPI write: 0x1e00
    SPI read: 0x0
    reg 1e: 0
    SPI write: 0x2000
    SPI read: 0x0
    reg 20: 0
    SPI write: 0x2200
    SPI read: 0x0
    reg 22: 0
    SPI write: 0x2400
    SPI read: 0x0
    reg 24: 0
    SPI write: 0x2600
    SPI read: 0x0
    reg 26: 0
    SPI write: 0x2800
    SPI read: 0x0
    reg 28: 0
    SPI write: 0x2a00
    SPI read: 0x0
    reg 2a: 0
    SPI write: 0x2c00
    SPI read: 0x0
    reg 2c: 0
    SPI write: 0x2e00
    SPI read: 0x0
    reg 2e: 0
    SPI write: 0x3000
    SPI read: 0x0
    reg 30: 0
    SPI write: 0x3200
    SPI read: 0x0
    reg 32: 0
    SPI write: 0x3400
    SPI read: 0x140
    reg 34: 140
    SPI write: 0x3600
    SPI read: 0x0
    reg 36: 0
    SPI write: 0x3800
    SPI read: 0x0
    reg 38: 0
    SPI write: 0x3a00
    SPI read: 0x3
    reg 3a: 3
    SPI write: 0x3c00
    SPI read: 0x80
    reg 3c: 80
    SPI write: 0x3e00
    SPI read: 0x0
    reg 3e: 0
    SPI write: 0x4000
    SPI read: 0x0
    reg 40: 0
    SPI write: 0x4200
    SPI read: 0x0
    reg 42: 0
    SPI write: 0x4400
    SPI read: 0x0
    reg 44: 0
    SPI write: 0x4600
    SPI read: 0x0
    reg 46: 0
    SPI write: 0x4800
    SPI read: 0x0
    reg 48: 0
    SPI write: 0x4a00
    SPI read: 0x0
    reg 4a: 0
    SPI write: 0x4c00
    SPI read: 0x0
    reg 4c: 0
    SPI write: 0x4e00
    SPI read: 0x0
    reg 4e: 0
    SPI write: 0x5000
    SPI read: 0x0
    reg 50: 0
    SPI write: 0x5200
    SPI read: 0x326
    reg 52: 326
    SPI write: 0x5400
    SPI read: 0x1902
    reg 54: 1902
    SPI write: 0x5600
    SPI read: 0xbcd
    reg 56: bcd
    SPI write: 0x5800
    SPI read: 0x57
    reg 58: 57
    SPI write: 0x5a00
    SPI read: 0xb900
    reg 5a: b900
    SPI write: 0x5c00
    SPI read: 0x1
    reg 5c: 1
    SPI write: 0x5e00
    SPI read: 0x30f5
    reg 5e: 30f5
    SPI write: 0x6000
    SPI read: 0x1c
    reg 60: 1c
    SPI write: 0x6200
    SPI read: 0x0
    reg 62: 0
    SPI write: 0x6400
    SPI read: 0x0
    reg 64: 0
    SPI write: 0x6600
    SPI read: 0x0
    reg 66: 0
    SPI write: 0x6800
    SPI read: 0x0
    reg 68: 0
    SPI write: 0x6a00
    SPI read: 0x0
    reg 6a: 0
    SPI write: 0x6c00
    SPI read: 0x0
    reg 6c: 0
    SPI write: 0x6e00
    SPI read: 0x0
    reg 6e: 0
    SPI write: 0x7000
    SPI read: 0x0
    reg 70: 0
    SPI write: 0x7200
    SPI read: 0x0
    reg 72: 0
    SPI write: 0x7400
    SPI read: 0x0
    reg 74: 0
    SPI write: 0x7600
    SPI read: 0x0
    reg 76: 0
    SPI write: 0x7800
    SPI read: 0x0
    reg 78: 0
    SPI write: 0x7a00
    SPI read: 0x0
    reg 7a: 0
    SPI write: 0x7c00
    SPI read: 0xab4
    reg 7c: ab4
    SPI write: 0x7e00
    SPI read: 0x0
    reg 7e: 0
    END
    
    acc_alm_crash
    
     -- Just crash my shit up --
    Disable alarms from ALM_CTRL...
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0x3400
    SPI read: 0x140
    SPI write: 0xb440
    SPI write: 0xb501
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0x3400
    SPI read: 0x140
    SPI write: 0xb440
    SPI write: 0xb501
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0x3400
    SPI read: 0x140
    SPI write: 0xb440
    SPI write: 0xb501
    Clear alarm bands from flash...
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xbe00
    SPI write: 0xbf02
    Set band pointer to 4...
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xb004
    SPI write: 0xb100
    Set band bins: 100 - 200
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xa064
    SPI write: 0xa100
    SPI write: 0xa2c8
    SPI write: 0xa300
    Set band warn/crit (x-axis): 1 2
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xa401
    SPI write: 0xa500
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xaa02
    SPI write: 0xab00
    Save band registers to flash...
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xbe00
    SPI write: 0xbf10
    Set band bins: 100 - 200
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xa064
    SPI write: 0xa100
    SPI write: 0xa2c8
    SPI write: 0xa300
    Set band warn/crit (x-axis): 10 20
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xa40a
    SPI write: 0xa500
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xaa14
    SPI write: 0xab00
    Save band registers to flash...
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xbe00
    SPI write: 0xbf10
    Load band registers from flash, crash expected...
    SPI write: 0x8000
    SPI write: 0x8100
    SPI write: 0xbe00
    SPI write: 0xbf40
    OK
    END
    
    //sensor crashed
    

  • I believe the root of the problem was me trying to save data to an unerased part of the flash memory. I didn't remember that flash generally has to be block erased before it can be rewritten.