Gast
#2945298
Hallo zusammen,
ich versuche gerade mit einem Max1239 via At91sam7 zu kommunizieren.
Leider bekomme ich keine Daten.
Ich kann mir nicht erklären, warum der hier nicht so will wie ich es
gerne hätte. Hat da jemand evtl. eine Idee?
--------------------------------------------------------------
void startbit(void)
{
SCL_SET_LOW;
SDA_SET_HIGH;
delay_us(Time_Twi);
SCL_SET_HIGH;
delay_us(Time_Twi);
SDA_SET_LOW;
delay_us(Time_Twi);
}
void stopbit(void)
{
SCL_SET_LOW;
SDA_SET_LOW;
delay_us(Time_Twi);
SCL_SET_HIGH;
while(!SCl_IS_HIGH);
delay_us(Time_Twi);
SDA_SET_HIGH;
delay_us(Time_Twi);
}
void Twi_Read_Byte(unsigned char* byte) {
unsigned char i;
SCL_SET_LOW;
SDA_SET_HIGH;
delay_us(Time_Twi);
for (i=0;i<8;i++)
{
*byte<<=1;
SCL_SET_HIGH;
delay_us(Time_Twi);
if((Twi_PIO->PIO_PDSR & SDA_MASK)==1) {
*byte |= 0x01;
}
else {
*byte &= ~(0x01); //0xFF;
}
SCL_SET_LOW;
}
//9th cycle
SCL_SET_LOW;
SDA_SET_HIGH;
delay_us(Time_Twi);
SCL_SET_HIGH;
while(!SCl_IS_HIGH);
delay_us(Time_Twi);
}
void ADC_MAX1239_init(void)
{
startbit(); // device address & write mode
Twi_Send_Byte(0b10100010); // write Register
Twi_Send_Byte(0b00010111); // write Register
stopbit(); // stop i2c
}
#define Adr_MAX1239 0b01101010
// MAX1239
void I2C_ADC_MAX1239(void)
{
unsigned int Data_Array_Messwert[11];
unsigned char hig,low = 0;//
unsigned char i;
// I2C MAX1239 - 12Bit ADC
startbit();
for ( i=0; i<=10;i++)
{
low = Twi_Read_Byte();
low &= ~((1 << 7) | (1<<6)| (1<<5)| (1<<4) );
hig = Twi_Read_Byte();
Data_Array_Messwert[i] = ((low << 8)| hig);
Data_Array_Messwert[i] = Data_Array_Messwert[i]*1.221001221;
}
stopbit();
}
Gruß