Skip to main content
Graduate
June 26, 2025
Solved

AIS2120SX sensor read data issue

  • June 26, 2025
  • 12 replies
  • 1351 views

Hi , i am trying to read the sensor data of AIS2120x only for sensor ID type , i can see from the bus the data is transferred correctly, but i don't receive any data back from sensor rather its only 0.

i have attached the code snippet for this test, any leads will be helpful. 

@JHo.1 and @Eleon BORLINI @CJeff.1 

 

test 1:
CS_low();
Sensor_Write(0xD1,0x80,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
// according to 32 byte cmmand format 
Sensor_Write(0x00,ubCrcVal,ubAisSensor ); 
CS_high();
 
Test 2:
CS_low();
Sensor_Write(0x8C,0x00,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
set_high();

//Sensor interface 

void Sensor_Write(uint8 addr, uint8 Data,(uint8 Sensor) {
 // application specific
spi_Write(addr);
delay();
spi_Write(Data);
}

//receive ISR
uint8 ubSpiStatus;
uint8 RxData;
_INTERRUPT_VOID SPI_vRxISR (void)
{
if(SPIS==0xA0)
{
RxData = SPID;
ubSpiStatus = 1;
}

}
spi_Write(uint8 addr, uint8 Data,uint8 ubAisSensor)
{
while (!(SPIS)); // Wait until transmit buffer is empty
SPID = data;

while(!ubSpiStatus);
ubSpiStatus = 0;

while (!(SPIS)); // Wait until transmit buffer is empty
SPID = data;

while(!ubSpiStatus);
ubSpiStatus = 0;
appl(RxData); //evaluate data
}

i use nxp 8 bit mcu : MC9S08SH32

MCU is 5v output, level shifter used between MCU and sensor to downgrade voltage to 3V3 ,

 

    This topic has been closed for replies.
    Best answer by anandhram1988

    Its worked now(change is downscaled the spi clock to 500K), thanks all for the reply, but still i am not sure why the clock frequency must be less than 1Mhz even datasheet says 5Mhz.

    12 replies

    Super User
    June 26, 2025

    You seem to have forgotten how to post source code ?

     


    @anandhram1988 wrote:

     i don't receive any data back from sensor rather its only 0.


    Your code uses only spi_Write() - there are no reads!

    Graduate
    June 26, 2025

    I have edited, the receive ISR, please inform if anything else required 

    Super User
    June 26, 2025

    Please read  how to post source code - apply the proper formatting.

    You need to show your implementation of spi_Write().

     

    You haven't said what microcontroller you're using, what board it's on. or how it's connected to the sensor.

    Please show schematics.

    See: How to write your question to maximize your chances to find a solution.

    Graduate
    June 26, 2025

    Thanks for reply,updated the main message also

    spi_Write(uint8 data)
    {
    while (!(SPIS)); // Wait until transmit buffer is empty
    SPID = data)

    while(!ubSpiStatus);
    ubSpiStatus = 0;
    appl(RxData); //evaluate data
    }

    i use nxp 8 bit mcu : MC9S08SH32

    MCU is 5v output, level shifter used between MCU and sensor to downgrade voltage to 3V3 ,

    anandhram1988_0-1750936410790.png

    SPI bus log attached

    Super User
    June 26, 2025

    You still haven't read how to post source code - have you?

    https://community.st.com/t5/community-guidelines/how-to-insert-source-code/ta-p/693413

     


    @anandhram1988 wrote:

    MCU is 5v output, level shifter used between MCU and sensor to downgrade voltage to 3V3


    Again, Please show the schematic!

     


    @anandhram1988 wrote:

    SPI bus log attached


    Is that before or after the level shifter?

    Show what's actually happening at the sensor's pins.

    Have you also looked at the signals on an oscilloscope? Are they clean?

     

    PS:

     


    @anandhram1988 wrote:

    i use nxp 8 bit mcu : MC9S08SH32. MCU is 5v output,


    That device can run at 3.3V.

    As a test, have you tried without the level shifter - running the MCU at 3.3V ?

    Graduate
    June 26, 2025
    test 1:
    CS_low();
    spi_Write(0xD1,0x80,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
     // according to 32 byte cmmand format spi_Write(0x00,ubCrcVal,ubAisSensor ); 
    CS_high();
     
    Test 2:
    CS_low();
    spi_Write(0x8C,0x00,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
    set_high();
     
    //receive ISR
    uint8 ubSpiStatus;
    uint8 RxData;
    _INTERRUPT_VOID SPI_vRxISR (void)
    {
    if(SPIS==0xA0)
    {
    RxData = SPID;
    ubSpiStatus = 1;
    }
     
    }
    spi_Write(uint8 data)
    {
    while (!(SPIS)); // Wait until transmit buffer is empty
    SPID = data;
    
    while(!ubSpiStatus);
    ubSpiStatus = 0;
    appl(RxData); //evaluate data
    }
    Super User
    June 26, 2025

    @anandhram1988 wrote:
    test 1:
    CS_low();
    spi_Write(0xD1,0x80,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
     // according to 32 byte cmmand format spi_Write(0x00,ubCrcVal,ubAisSensor ); 
    CS_high();
     
    Test 2:
    CS_low();
    spi_Write(0x8C,0x00,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
    set_high();

    In the above code, you supply three parameters to each spi_Write() call

    But your definition of spi_Write() takes only one parameter


    @anandhram1988 wrote:
    spi_Write(uint8 data)
    {

     

    Also:

    @anandhram1988 wrote:

    i use nxp 8 bit mcu : MC9S08SH32. MCU is 5v output,

    That device can run at 3.3V.

    As a test, have you tried without the level shifter - running the MCU at 3.3V ?

    Graduate
    June 26, 2025
    test 1:
    CS_low();
    Sensor_Write(0xD1,0x80,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
     // according to 32 byte cmmand format Sensor_Write(0x00,ubCrcVal,ubAisSensor ); 
    CS_high();
     
    Test 2:
    CS_low();
    Sensor_Write(0x8C,0x00,ubAisSensor ); // command to read address 0x0C/REG_ID_SENSOR_TYPE from AIS2120x
    set_high();
    
    //Sensor interface 
    
    void Sensor_Write(uint8 addr, uint8 Data,(uint8 Sensor) {
     // application specific
    	spi_Write(addr);
    	delay();
    	spi_Write(Data);
    }
     
    //receive ISR
    uint8 ubSpiStatus;
    uint8 RxData;
    _INTERRUPT_VOID SPI_vRxISR (void)
    {
    if(SPIS==0xA0)
    {
    RxData = SPID;
    ubSpiStatus = 1;
    }
     
    }
    spi_Write(uint8 addr, uint8 Data,uint8 ubAisSensor)
    {
    while (!(SPIS)); // Wait until transmit buffer is empty
    SPID = data;
    
    while(!ubSpiStatus);
    ubSpiStatus = 0;
    
    while (!(SPIS)); // Wait until transmit buffer is empty
    SPID = data;
    
    while(!ubSpiStatus);
    ubSpiStatus = 0;
    appl(RxData); //evaluate data
    }
    Graduate
    June 26, 2025

    SPI trace attached already from the sensor pins, i have not tried with 3,3MCU voltage since 5 V is operating for this mcu

    anandhram1988_0-1750940479516.png

     

    Above trace is recorded from sensor pins

    Graduate
    June 26, 2025

    @Andrew Neil  this is the complete code after formatting and actual tested version

    please look :)

    Graduate
    June 26, 2025

    @Andrew Neil could you please support, i am really blocked

    Super User
    June 26, 2025

    I given you all the suggestions I have.

    Graduate
    June 26, 2025

    i have also tried with 3.3V MCU inputs problem is still same

    Graduate
    June 27, 2025

    @Andrew Neil can this IC works alone with 4mhz clock please confirm

    Technical Moderator
    June 27, 2025

    According to its data sheet, table 49, the SPI of the AIS2120 can work up to max 5MHz.

    But it expects 32-bit frames, which is also mentioned in the data sheet, section 5. Your screenshot of a frame only shows 16-bits?

    [edit] Anyway - the AIS2120 has long been cancelled, no further support is possible anymore. [/edit]

    Regards
    /Peter

    Graduate II
    June 27, 2025

    The AIS2120x sensor doesn't even exist! This is a photomos, not a sensor. I assume you meant the AIS2120SX. Which is an acceleration sensor.
    You can edit previous posts. You don't need to make new posts to provide corrections for old posts. And posting twice in a row, called double posting, is not done on forums.  Please edit the question/title and posts so it refers to the correct part number. This way more people can help and other people who have an issue can come here if it is solved.

    Also please properly format code and add real schematics like Andrew Neil suggested. You can also add a photo of your setup. We don't have a crystal ball so we don't know what you don't share.

    My hypothesis is that the cause is being disorganized. Forgot to connect a wire. Reversed the voltage. ESD. Wrong MCU pin. Etc.