Hi,
We are using simulated GPIOs for one wire communication, to interface MC9S12ZI128 controller to humidity & temperature sensor (BM25S2021-1). But we are unable to read the status of sensor on GPIO pin. I think it is delay issue, please suggest whether it is correct or not. If i am wrong suggest me what is the exact problem.Here i am posting the code what i written.
void delay(u16 count) {
int i;
for(i=0;i<count;i++)
{
Nop();
}
}
void One_wire_start()
{
DDRA=0x4E;
Clear();
delay(1565);
Set();
delay(43);
}
u8 One_wire_ack(u8 *cnt)
{
u8 cnt;
DDRA=0x0E;
*cnt = _PTIA.Bits.PTIA6;
}
void Humidity(u8 *cnt)
{
u8 ow_op;
while(1)
{
One_wire_start();
One_wire_ack(cnt);
ow_op = OW_Read_Byte();
}
}
void Set()
{
PTA_PTA6 = 0x01;
}
void Clear()
{
PTA_PTA6 = 0x00;
}
char Poll_SO_OW()
{
unsigned char temp = 0;
Clear();
while (temp == 0x00) / waste time until not busy /
temp = ReadSO_OW();
Set();
}
char ReadSO_OW()
{
if (PTA & 0x1) return 1;
else return 0;
}
unsigned char OW_Get_Byte()
{
unsigned char i = 0, in = 0, temp = 0;
for (i = 0; i < 8; i++)
{
in = (in << 1); / shift 1 place to the left or shift in 0 /
temp = Poll_SO_OW(); / save input /
if (temp == 1) { / check to see if bit is high /
in = in | 0x01; / if high, make bit high /
}
}
return in;
}
unsigned char OW_Read_Byte()
{
unsigned char byte = 0;
Clear(); / enable device /
byte = OW_Get_Byte();
Set(); / disable device /
return byte; / return one byte read /
}
Hi,
We are using simulated GPIOs for one wire communication, to interface MC9S12ZI128 controller to humidity & temperature sensor (BM25S2021-1). But we are unable to read the status of sensor on GPIO pin. I think it is delay issue, please suggest whether it is correct or not. If i am wrong suggest me what is the exact problem.Here i am posting the code what i written.
void delay(u16 count) {
int i;
for(i=0;i<count;i++)
{
Nop();
}
}
void One_wire_start()
{
DDRA=0x4E;
Clear();
delay(1565);
Set();
delay(43);
}
u8 One_wire_ack(u8 *cnt)
{
u8 cnt;
DDRA=0x0E;
*cnt = _PTIA.Bits.PTIA6;
}
void Humidity(u8 *cnt)
{
u8 ow_op;
while(1)
{
One_wire_start();
One_wire_ack(cnt);
ow_op = OW_Read_Byte();
}
}
void Set()
{
PTA_PTA6 = 0x01;
}
void Clear()
{
PTA_PTA6 = 0x00;
}
char Poll_SO_OW()
{
unsigned char temp = 0;
Clear();
while (temp == 0x00) / waste time until not busy /
temp = ReadSO_OW();
Set();
}
char ReadSO_OW()
{
if (PTA & 0x1) return 1;
else return 0;
}
unsigned char OW_Get_Byte()
{
unsigned char i = 0, in = 0, temp = 0;
for (i = 0; i < 8; i++)
{
in = (in << 1); / shift 1 place to the left or shift in 0 /
temp = Poll_SO_OW(); / save input /
if (temp == 1) { / check to see if bit is high /
in = in | 0x01; / if high, make bit high /
}
}
return in;
}
unsigned char OW_Read_Byte()
{
unsigned char byte = 0;
Clear(); / enable device /
byte = OW_Get_Byte();
Set(); / disable device /
return byte; / return one byte read /
}