Micrel MIC74 (I2C based) with CodeVision AVR problem

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

This is me again Joseph. I have a problem changing the speed of MIC74 fan speed controller via I2C interface between AVR AT90S8515 and MIC74(from Micrel Semiconductor). I have been trying again and again to change the speed but it doesn't want to change. Did I miss anything?

Is my I2C read and write sequence wrong? I use the I2C lib from Pavel
Here's the code:

/*********************************************
This program was produced by the
CodeWizardAVR V1.23.5 Evaluation
Automatic Program Generator
© Copyright 1998-2002 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro , hpinfotech@xnet.ro

Project : FanControl#1
Version : 1.0
Date : 12/4/2002
Author : Joseph Tjoharno
Company :
Comments:
Fan Control using MIC74 and AT90S8515 and I2C

Chip type : AT90S8515
Clock frequency : 4.000000 MHz
Memory model : Small
Internal SRAM size : 512
External SRAM size : 0
Data Stack size : 128
*********************************************/
#include

// I2C Bus & LCD functions
#asm
.equ __lcd_port=0x15 ;port C is used for LCD
#endasm

#asm
.equ __i2c_port=0x12 ;port D is used for I2C
.equ __sda_bit=4
.equ __scl_bit=2
#endasm

#include
#include
#include
#include

sfrb PORTA=0x1b;
sfrb DDRA=0x1a;
sfrb PINA=0x19;

sfrb PORTD=0x12;
sfrb DDRD=0x11;
sfrb PIND=0x10;

unsigned char mic74_read(unsigned char address)
{
unsigned char data;
i2c_start();
i2c_write(0x20);
i2c_write(address);
i2c_start();
i2c_write(0x20 | 1);
data=i2c_read(0);
i2c_stop();
return data;
}

void mic74_write(unsigned char address, unsigned char data)
{
i2c_start();
i2c_write(0x20);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(5);
}

void lcd_display(char old, char new)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_putchar(old);
lcd_gotoxy(0,1);
lcd_putchar(new);
}

void main(void)
{
unsigned char old, new;

i2c_init();
lcd_init(16);
lcd_clear();

while (1)
{
old=mic74_read(0x06);
//this is the address of DEV_CFG & the value I want to put into MIC74
mic74_write(0x00,00000010);
//this is the address of FAN_SPEED register & the value I want to put into it
mic74_write(0x06,00000011);
new=mic74_read(0x06);
lcd_display(old,new);
}
}