Hi,
I am using MMA8452 in one of the projects I am working on and am facing some problem when trying to read the device configuring the interrupts. The interrupt line stays active low/ active high on the device so my interrupt never vectors to the ISR thread.
1. I am doing the following configuration setting on the device
i2c_RegRead(CTRL_REG1,SINGLE_BYTE,&tx_para[0]);
i2c_RegWrite(CTRL_REG1, tx_para[0]& ~(ACTIVE_MASK));
i2c_RegWrite(CTRL_REG1, DATA_RATE_1250US);
i2c_RegWrite(XYZ_DATA_CFG_REG, FULL_SCALE_8G);
i2c_RegWrite(CTRL_REG3, 0);
i2c_RegWrite(CTRL_REG4, INT_EN_DRDY);
i2c_RegWrite(CTRL_REG5, INT_CFG_DRDY); // send on pin1
i2c_RegRead(CTRL_REG1,SINGLE_BYTE,&tx_para[0]);
i2c_RegWrite(CTRL_REG1, tx_para[0]& (ACTIVE_MASK));
q.num_bytes = ARRAY_SIZE;
if (ioctl(fd, CONFIG_DEVICE, &q) == -1)
{
perror("query_apps ioctl set\n");
}
printf("configured values :\n");
i2c_RegRead(CTRL_REG1, 1,&tx_para[0]);
printf("value at address:0x%2X is 0x%X\n",CTRL_REG1,tx_para[0]);
i2c_RegRead(XYZ_DATA_CFG_REG, 1,&tx_para[0]);
printf("value at address:0x%2X is 0x%X\n",XYZ_DATA_CFG_REG,tx_para[0]);
i2c_RegRead(CTRL_REG3, 1,&tx_para[0]);
printf("value at address:0x%2X is 0x%X\n",CTRL_REG3,tx_para[0]);
i2c_RegRead(CTRL_REG4, 1,&tx_para[0]);
printf("value at address:0x%2X is 0x%X\n",CTRL_REG4,tx_para[0]);
i2c_RegRead(CTRL_REG5, 1,&tx_para[0]); // send on pin1
printf("value at address:0x%2X is 0x%X\n",CTRL_REG5,tx_para[0]);
// read the xyz data registers to assert the interrupt the same is assertedlater on in the module. so I expect to fire the interrupt from this point onwards
q.buff[0] = 0x01;
q.num_bytes = 6; //< 10 !!
// unsigned int i = 0 ;
if (ioctl(fd, MMA8452_IOC_READ_NBYTES, &q) == -1)
{
perror("query_apps ioctl get");
}
else
{
for(i = 0 ; i < q.num_bytes ; i ++)
{
printf("Read Data %d\n", q.buff[i]);
}
}
the IOCTL module is my own cosutom module , I can read from and write to the device using the same so I am confident that the module is otherwise functional.
I am configuring the interrupts on line INTR1 and reading the data registers first time after that I am reading the status and the data registers in interrupt in the module as follows:
irq_handler_t thread_fn(void)
{
//struct timespec t;
time_t curr_time ; // get time now
struct tm * now ;
printk(KERN_ERR "in_intr...\n");
char status,reg;
//struct Accel_data Axis_dat_thread0[SINGLE_DATA_SET_K],Axis_dat_thread1[SINGLE_DATA_SET_K];
//static isr_thread,current_set = 0;
// NEED TO READ THE intr source bit as well
reg = 0x0C;
mma8452_i2c_rx_data(reg,1,&status);
if( status & 0x01)
{
reg = MMA8452_REG_DATA;
if ( mma8452_i2c_rx_data(reg,6,&raw_axis_data[0]) < 0 ) // change
{
return -EFAULT;
}
}
the interrupt is configured as follows
status = request_threaded_irq (irq_num,NULL,(irq_handler_t)thread_fn,IRQF_TRIGGER_FALLING|IRQF_ONESHOT,"MMA8452_intr1",NULL);
Can some one kindly guide me what could be going wrong ? I am not putting the process to sleep anywhere.
Regards,
cn.