Als eindwerk moeten ik en een vriend via een DK41 starterkit (embedded webserver) de temperatuur uitlezen, om de temperatuur te weten te komen gebruiken we de DS1621 een IC die gebruikt maakt van I²C...
De webserver valt te programmeren in C, onze code is:
#include <stdio.h>
#include <conio.h>
#include "clib.h"
void main(void)
{
char temp[3]; temp[2]='\0';
I2C_init();
RTX_Sleep_Time(3000);
I2C_transmit_char(144,0XEE);
printf("\nverzenden van start command\n");
I2C_transmit_char(144,0XAA);
printf("\nTransmit = done ==> 3s wachten");
RTX_Sleep_Time(3000);
//I2C_restart();
//printf("\nRestart = done ==> 3s wachten");
//RTX_Sleep_Time(3000);
I2C_receive_block(144,temp,2);
printf("\nReceive = done ==> 3s wachten");
RTX_Sleep_Time(3000);
I2C_release();
printf("\nRelease = done ==> 3s wachten");
RTX_Sleep_Time(3000);
printf("\n temp : %c%C Celsius",temp[0],temp[1]);
printf("\n temp\n");
printf(temp);
}
Maar het werkt echter niet, kan iemand ons helpen?
Dank bij voorbaat.
HBontekoe
iets zonder duidelijke functie is vaak meer waard als iets nuttigs...
zet je code tussen de [code ] [/code ] tags.. dat maakt het al overzichtelijker..
verder ook wel interesant wat je ervaring in programmeren is..
Dit vond ik op de website van de embedded webserver,
http://www.beck-ipc.com/ipc/download/load.asp?id=3035&sp=en:
/******************************************************************************
*
* (c) 2004 by BECK IPC GmbH
*
*******************************************************************************
*
* Disclaimer: This program is an example and should be used as such.
* If you wish to use this program or parts of it in your application,
* you must validate the code yourself. BECK IPC GmbH can not be held
* responsible for the correct functioning or coding of this example.
*
* Module: i2c_lm75.c
* Function: I2C bus example for LM75 temperature sensor
* Author: Stefan Perzborn
*
*******************************************************************************
*
* $Header: I2C_LM75.C, 4, 29.08.2005 13:09:06, Andre Pribil$
*
******************************************************************************/
/******************************************************************************
* Includes
******************************************************************************/
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <conio.h>
#include "clib.h"
/******************************************************************************
* Main
******************************************************************************/
int main (void)
{
float temp_LM75=0;
char byte0, byte1;
unsigned int result;
unsigned int adress_LM75;
printf("\nI2C LM75 Temperature Example\n");
//Init I2C bus
printf("\nInit I2C bus...");
I2C_select_clock_pin ( 10 );
I2C_select_data_pin ( 9 );
I2C_init();
//scan for I2C slave
printf("\nScanning I2C bus for LM75... " );
result = I2C_scan(0x90, 0x9F);
if(result < 1)
{
printf("\nError: LM75 not found, I2C scan error %d",result);
}
else
{
adress_LM75 = result;
printf("\nLM75 found at 0x%02X",adress_LM75);
//Set IO_focus to program
BIOS_Set_Focus(FOCUS_APPLICATION);
while (!kbhit())
{
RTX_Sleep_Time(500);
I2C_receive_char (adress_LM75, &byte0, 1);
temp_LM75 = byte0;
I2C_receive_char (adress_LM75, &byte1, 0);
if ((byte1 & 128) == 128)
{
temp_LM75 += 0.5;
}
printf("\nLM75 temperature: %3.1f 'C",temp_LM75);
I2C_release();
}
//set IO_focus to default
printf("\nExit program\n");
BIOS_Set_Focus(FOCUS_BOTH);
}
//Release
I2C_release();
return 0;
}
Volgens mij moet hier toch wel uit te komen zijn.
Alle benodigde bibliotheken zijn hier ook te downloaden.