2025-06-26 3:48 AM - last edited on 2025-06-27 10:42 AM by mƎALLEm
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
@JHo.1 and @Eleon BORLINI @CJeff.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();
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 ,
Solved! Go to Solution.
2025-06-26 5:34 AM - edited 2025-06-26 5:47 AM
i have edited the code now(test), i cannot paste the appl code. sorry for that
from the schematic, 5v fixed is provided hence not tried without levelshifter and 3,3 mcu operating voltage
I would like to have below information:
commands to be written into spi for getting response form sensor.
2025-06-26 6:21 AM
Again, you haven't formatted the code.
I'm out.
2025-06-26 6:39 AM
volatile UB__8 ubAisRxData;
volatile UB__8 ubSpiStatus = 0;
void SPI_vInit(void) {
disable_interrupts();
configure_D_OUT_SPI_MOSI_Pin(); // PTBDD_PTBDD5 = 1; // MOSI
configure_D_IN_SPI_MISO_Pin(); //PTBDD_PTBDD4 = 0; // MISO
configure_D_OUT_SPI_CLK_Pin(); // PTBDD_PTBDD6 = 1; // SCK
set_CS1_high(); // Sensor 1 disable
set_CS2_high(); // Sensor 2 disable
// SPI Control Register 1
SPIC1 = 0xD4; // SPE=1, MSTR=1, SSOE=0, CPOL=0, CPHA=0, SPIE=1
//SPIC1 = 0xF0; // SPE=1, MSTR=1, SSOE=0, CPOL=0, CPHA=0, SPIE=1
// SPI Control Register 2
SPIC2 = 0x00;
// SPI Baud Rate Register (set to suitable speed)
//SPIBR = 0x10; // Divide bus clock 16 Mhz, spi clock 5,33Mhz
SPIBR = 0x11; // Divide bus clock 16 Mhz, spi clock 4 Mhz
// Clear status flags by reading SPIS and SPID
(void)SPIS;
(void)SPID;
enable_interrupts();
}
void SPI_vSendByte(UB__8 ubSpiTransfer, UB__8 ubSpiChannel)
{
volatile UB__8 ubAisStatus;
volatile UB__8 ubAisRx;
while (!(SPIS)); // Wait until transmit buffer is empty
SPID = ubSpiTransfer;
while(!ubSpiStatus);
ubSpiStatus = 0;
}
_INTERRUPT_VOID SPI_vTransferISR (void)
{
if(SPIS==0xA0)
{
ubAisRxData = SPID;
ubSpiStatus = 1;
}
}
UB__8 AIS1120SX_ubSensorConfig(UB__8 ubAisSensor)
{
UW_16 readVal;
UB__8 retVal = 0;
UB__8 ubCrcVal;
UW_16 delay;
ubCrcVal = AIS1120SX_ubCrcVal (0xE18000); // to read 0c0C register from sensor Sensor type Val
set_CS1_low();
for(delay =0; delay < 10; delay++);
AIS1120SX_vWrite(0xE1,0x80,ubAisSensor ); // REG_CONFIG FIR is 1600 for X,Y and
//no ofset cancellation
AIS1120SX_vWrite(0x00,ubCrcVal,ubAisSensor ); // REG_CONFIG FIR is 1600 for X,Y and
// AIS1120SX_vWrite(0x8D,0x00,ubAisSensor );
// for(delay =0; delay < 10; delay++);
// AIS1120SX_vWrite(0x00,0x00,ubAisSensor );
set_CS1_high();
return retVal;
}
void AIS1120SX_vWrite(UB__8 ubAis_addr, UB__8 ubAisData,UB__8 ubAisSensor) {
UW_16 delay;
SPI_vSendByte(ubAis_addr, ubAisSensor);
SPI_vSendByte(ubAisData, ubAisSensor);
}
UB__8 AIS1120SX_ubCrcVal(UL_32 ulCrcVal) {
UB__8 crc = 0x00;
UB__8 poly = 0x97;
//UL_32 poly = 0x12F;
UB__8 i;
UB__8 b;
// Process only the top 3 bytes of data24 (ignoring the lowest byte)
for (i = 0; i<3; i++)
{
crc ^= (UB__8)((ulCrcVal >> (i * 8)));
for (b = 0; b < 8; b++)
{
if (crc & 0x80)
{
crc = (UB__8)((crc << 1) ^ poly);
}
else
{
crc <<= 1;
}
}
}
return crc;
}
2025-06-26 6:39 AM - edited 2025-06-26 7:49 AM
@Andrew Neil this is the complete code after formatting and actual tested version
please look :)
2025-06-26 8:37 AM
@Andrew Neil could you please support, i am really blocked
2025-06-26 8:38 AM
I given you all the suggestions I have.
2025-06-26 9:52 AM
i have also tried with 3.3V MCU inputs problem is still same
2025-06-27 5:35 AM
@Andrew Neil can this IC works alone with 4mhz clock please confirm
2025-06-27 6:08 AM - edited 2025-06-27 6:13 AM
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
2025-06-27 6:10 AM - edited 2025-06-27 6:12 AM
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.