zia
Full Member level 5
- Joined
- Sep 24, 2010
- Messages
- 284
- Helped
- 27
- Reputation
- 54
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Islamabad Pakistan
- Activity points
- 2,746
i want to share my sames sa9904bsome code for your help
get data by this way
#define CS PORTD.F2 // or any other pin for spi chip selection
long read_reg(char adr)
{
long x=0;
char d1=0,d2=0,d3=0;
CS = 1;
Spi_Write(1);
Spi_Write(adr | 0x80);
d1=Spi_Read(0);
d2=Spi_Read(0);
d3=Spi_Read(0);
CS = 0;
l1 = d3*65536 + d2 *256 +d1;
return l1;
}
void main(void)
{
Spi_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, HIGH_2_LOW);
TRISD.F2 = 0; // CS output
CS = 0;
for(;
{
active_power_count=read_reg(0);
ractive_power_count=read_reg(0);
freq=read_reg(0);
voltage=read_reg(0);
///process all of these according to datasheet
}
}
get data by this way
#define CS PORTD.F2 // or any other pin for spi chip selection
long read_reg(char adr)
{
long x=0;
char d1=0,d2=0,d3=0;
CS = 1;
Spi_Write(1);
Spi_Write(adr | 0x80);
d1=Spi_Read(0);
d2=Spi_Read(0);
d3=Spi_Read(0);
CS = 0;
l1 = d3*65536 + d2 *256 +d1;
return l1;
}
void main(void)
{
Spi_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, HIGH_2_LOW);
TRISD.F2 = 0; // CS output
CS = 0;
for(;
{
active_power_count=read_reg(0);
ractive_power_count=read_reg(0);
freq=read_reg(0);
voltage=read_reg(0);
///process all of these according to datasheet
}
}
Last edited: