以前チョコさんが投稿していたIICのプログラムを参考にして、センサ値を取得しLCDに表示するプログラムを作成しているのですがうまく温度センサから値を得ることができません。
使用しているマイコンはRL78/G13、センサはMLX90614を使用しています。変更したところを載せますので間違いなどを指摘していただきたいです。
void main(void){ MD_STATUS status; uint8_t main_loopc; /* loop counter for main loop */ uint8_t i; /* loop counter for subloop */ uint8_t j; /* loop counter for subloop */ uint8_t k; /* loop counter for subloop */ uint8_t __far const *pt_txdata; /* write data to slave pointer */ uint8_t *pt_ram; /* read RAM data pointer */ uint8_t reg_addr; /* register address in slave */ uint8_t temp_data; /* work area for read data */ uint8_t ram_valid; /* RAM data is valid flag */
ram_valid = FALSE; /* start with RAM is not valid */ main_loopc = 0x06; /* write data buffer number */ //int b = 0; /* Start user code. Do not edit comment generated here */ P7 = 0x00; RS_PIN =0; RW_PIN = 0; EN_PIN = 0; BUZZER_PIN = 0;// R_MAIN_UserInit(); /*LCD Intialization*/ InitialiseDisplay(); /*LCD Title Disp*/ TitleDisp(); temp_data = 0; CharacterDisp(temp_data);
/* Display information on the debug LCD. */ //DisplayString(LCD_LINE1, (int8_t*)" test "); //DisplayString(LCD_LINE2, (int8_t*)"Running."); /*AD change*/ /*buzzer start*/ //StartupBuzzer(); while (1U) { for ( j = 0x00 ; j < 0x08 ; j++ ) { pt_ram = (uint8_t *)&g_read_ram[j][0]; reg_addr = (RAM_TOP + j*0x10); status = g_IIC_get_data( SLAVE_ADDR, reg_addr, pt_ram, 0x10 ); while ( status ) /* wait for success to read */ { NOP(); } }
/* Test3 : check read data of RAM*/
if( TRUTH == ram_valid ) { for ( i = 0 ; i < 8 ; i++ ) /* check read 1st 64 bytes data */ { for ( j = 0 ; j < 16 ; j++ ) { k = i >> 2; temp_data = ((( i & 0b00000011 ) * 16 ) + j); /* get offset for 64 */ temp_data = ram_data[main_loopc+k][temp_data]; /* get data */ } } } CharacterDisp(temp_data); } /* End user code. Do not edit comment generated here */}