README.TXT 1) TEMPSENS.C 1.a)defines 1.b)functions 1.c)main 2) TEMPSENS2.C (version 1.13) 2.a)defines 2.b)functions 2.c)main 3) TEMPSENS2.C (later versions) 3.a)defines 3.b)functions 3.c)main 4) SERIALTRX.C 4.a)defines 4.b)functions 4.c)main 5) SOCKET.C & FILEPRL.PL 5.a)defines 5.b)functions 5.c)main A)needed files 1)TEMPSENS.C tempsens.c is a program which allows you to read from 1 Dallas ds1820 device the temperature and his 64 bits ID number. it works also with many devices on the bus, but allows to read the temperature and ID just from one 1.a) BUSES: set the pin bitmask were the 1-wire bus is linked to, in this case is setted on the first pin of the F port. to set different parameters, you have to change the definitions in OWIPolled.h (see appendix A) DS1820_START_CONVERSION here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start temperature conversion (see the ds1820 data sheet) DS1820_READ_SCRATCHPAD here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start sending the data stored in the scratchpad memory (see the ds1820 data sheet) 1.b) break_point(int,uint8_t*) this function sets an interrumption in the program. to run needs to be given as argument an integer and a char pointer when the function break_point is reached, the program will stop running, and on the screen will appear a message with the code number of the break_point, given as argument, useful to know wich break_point had been reached, the value of the char pointer given as argument, the character or the string which the pointer is pointing uint16_t readtemperature(uint8_t,uint8_t) this function will return the value of the temperature read by the sensor. It asks for a bitmask of the pin which the sensor is linked and for a pointer to an array of char of size 8 in which is stored the device ID. It returns a value inferior to -900 if an error occurs (for example the wanted devices is not connected to the given bus). the function will check the presence of the device (operation which also works as a reset pulse), then send the match_rom command which allows only the selected device to answer to the following command, and then send the convertT command. when the devices receive the ConvertT command will start the analog to digital conversion and will write the result on the first 2 bytes of the scratchpad. then function will send another reset pulse followed by a matchRom command, and suddenly will ask the device to send the first 2 bytes of the scratchpad. the function will store them in the variable temperature and send a reset pulse again. for the functions used in ReadTemperature, see OWIHighLevelFunctions.c 1.c) in the main are inizialized the following variables: t is the variable in which is stored the temperature value sensname is a char array in which is stored the device ID str is a string where the data will be stored as ASCII res is the result of the SearcRom function (see http://www.maxim-ic.com/products/ibutton/ibuttons/standard.pdf for an explanation of the searchrom function) which is implemented in the file OWIHighLevelFunctions.c and defined in OWIHighLevelFunctions.h. PD is the result of the DetectPresenc function.( see OWISWBitFunctions.c )and is a bitmask of the pin on where the device has been found after turning on the power and initializing the bus, the program will start an infinite loop (whic terminates with a break_point) at the beginning will be created a bitmask of the bus (pins), and the will be sebt a reset pulse on the bus, followed by the searchrom command. then the temperature will be read and stored in t. after that on str will be printed a string with the result of the searc (80 if it was succesful); the deviceĀ“s ID in Hexadecimal and the temperature.due to converting format reason, if its needed to have the temperature in centigrad degres, is needed to divide the value of t for 16. (degrees temp=t/16) after that, the break_point will interrupt the loop and print the value of str. 2)TEMPSENS2.C (until version 1.13 ) tempsens2.c is a program which allows you to read from several Dallas ds1820 devices on a same bus the temperature and their 64 bits ID numbers. 2.a) BUSES: set the pin bitmask were the 1-wire bus is linked to, in this case is setted on the first pin of the F port. to set different parameters, you have to change the definitions in OWIPolled.h (see appendix A) DS1820_START_CONVERSION here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start temperature conversion (see the ds1820 data sheet) DS1820_READ_SCRATCHPAD here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start sending the data stored in the scratchpad memory (see the ds1820 data sheet) NUM_DEVICES here is defined the maximum number of devices the user wants to read from. if there are more devices, the program will run properly but will only read from NUM_DEVICES devices. 2.b)break_point(int,uint8_t*) this function sets an interrumption in the program. to run needs to be given as argument an integer and a char pointer when the function break_point is reached, the program will stop running, and on the screen will appear a message with the code number of the break_point, given as argument, useful to know wich break_point had been reached, the value of the char pointer given as argument, the character or the string which the pointer is pointing uint16_t readtemperature(uint8_t,uint8_t) this function will return the value of the temperature read by the sensor. It asks for a bitmask of the pin which the sensor is linked and for a pointer to an array of char of size 8 in which is stored the device ID. It returns a value inferior to -900 if an error occurs (for example the wanted devices is not connected to the given bus). the function will check the presence of the device (operation which also works as a reset pulse), then send the match_rom command which allows only the selected device to answer to the following command, and then send the convertT command. when the devices receive the ConvertT command will start the analog to digital conversion and will write the result on the first 2 bytes of the scratchpad. then function will send another reset pulse followed by a matchRom command, and suddenly will ask the device to send the first 2 bytes of the scratchpad. the function will store them in the variable temperature and send a reset pulse again. for the functions used in ReadTemperature, see OWIHighLevelFunctions.c 2.c) in the main are inizialized the following variables: t is an array where are stored the temperature values read by the devices IDS is a 2D char array in which are stored the devices IDs, any of them has size 8. regtemp is a string where the data will be stored as ASCII countDEV is an integer which counts the real number of devices placed on the bus. PD is the result of the DetectPresenc function.( see OWISWBitFunctions.c )and is a bitmask of the pin on where the device has been found after turning on the power and initializing the bus, the program will start an infinite loop (which terminates with a break_point) at the beginning will be created a bitmask of the bus (pins) and the variable res will be initialized as 1. res will be the result of the SearcRom function (see http://www.maxim-ic.com/products/ibutton/ibuttons/standard.pdf for an explanation of the searchrom function) which is implemented in the file OWIHighLevelFunctions.c and defined in OWIHighLevelFunctions.h. it has been initialized as 1 in order to force the entrance in the following for loop the first element of regtemp has to be initialized as a "\0" (end of string character) in order to make the function strcat work properly, and an element oof IDS is set as 0. countDEv is initialized as 0. A reset pulse is sent on the bus (this command is not strictly needed for running the program but storing the value of PD can be useful during the debug). The program will enter a for loop which will goes on until the maximum number of devices have been identified or all the devices have been identified. In the loop there will be the following operations: If is the first time the loop is being running, then res has to be set as 0, because there will be the first searcRom command which needs a 0 as second argument (see OWIHighLevelFunctions.c) after that check, a reset pulse is issued and asuddenly the searcRom can be issued. the last element of IDS will be every time overwritten, and time to time is stored in the first free element of IDS, until the last loop in whic the last element of IDS will be copied in itself. at every loop the countDEv counter is incremented by 1. after this, another for loop is issued. In this loop the data will be translated as ASCII on the string regtemp. In the loop there will be the following operations: for every device, will be readen the value of the temperature and this value will be stored in the correspondant element of t. a char string is initialized. on this string will be written the ID of the device in Hexadecimals and the temperature readen by the device, suddenly, with the strcat (see the stdlib.h library) command, this string will be pasted at the end of regtemp. at the end of the for loop, in regtemp will be sored all the IDs and the temperatures. Due to converting format reasons, if its needed to have the temperature in centigrad degres, is needed to divide the value of t for 16. (degrees temp=t/16) after that, the break_point will interrupt the loop and print the value of str. 3)TEMPSENS2.C (version later then 1.13) tempsens2.c is a program which allows you to read after receiving a command on USART register from several Dallas ds1820 devices on a same bus the temperature and their 64 bits ID numbers, and send this datas on a serial port. 3.a) BUSES: set the pin bitmask were the 1-wire bus is linked to, in this case is setted on the first pin of the F port. to set different parameters, you have to change the definitions in OWIPolled.h (see appendix A) DS1820_START_CONVERSION here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start temperature conversion (see the ds1820 data sheet) DS1820_READ_SCRATCHPAD here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start sending the data stored in the scratchpad memory (see the ds1820 data sheet) DS1820_WRITE_SCRATCHPAD here is defined the protocol which the master has to send on the 1-wire bus in order to be allowed to write on the devices' memory (see the ds1820 data sheet) NUM_DEVICES here is defined the maximum number of devices the user wants to read from. if there are more devices, the program will run properly but will only read from NUM_DEVICES devices. BAUD is the baud rate for the serial transmission. the formula for calculating the rigth value is given as comment. 3.b)break_point(int,uint8_t*) this function sets an interrumption in the program. to run needs to be given as argument an integer and a char pointer when the function break_point is reached, the program will stop running, and on the screen will appear a message with the code number of the break_point, given as argument, useful to know wich break_point had been reached, the value of the char pointer given as argument, the character or the string which the pointer is pointing uint16_t readtemperature(uint8_t,uint8_t) this function will return the value of the temperature read by the sensor. It asks for a bitmask of the pin which the sensor is linked and for a pointer to an array of char of size 8 in which is stored the device ID. It returns a value inferior to -900 if an error occurs (for example the wanted devices is not connected to the given bus). the function will check the presence of the device (operation which also works as a reset pulse), then send the match_rom command which allows only the selected device to answer to the following command, and suddenly will ask the device to send the first 2 bytes of the scratchpad. the function will store them in the variable temperature and send a reset pulse again. for the functions used in ReadTemperature, see OWIHighLevelFunctions.c int TempStored(uint8_t *, uint8_t ) this function perform all the operations which were setted in the main of tempsens2.c (version<1.14). see above for a description. The only difference is that the ConvertT command is no more placed in ReadTemp function but directly here in TempStored and before this command is sent the SKIP_ROM command which addresses all the devices at the same time. In this way all the devices will perform a conversion simoultaneously. it requires an array in which will be stored the devices' ID and a bitmask of the bus on which the devices are placed. int AlarmStored(uint8_t *, uint8_t ) this function works exactly in the same way of TempStored, but, as a different command is sent on the 1-wire bus, only those devices which are experiencing an alarm flag condition will be activated, and so only their temperature will be readen and only their ID will be stored void USARTn_Init (unsigned int) (note: n is 1 or 0) this function initialize the USARTn registers,in order to allow the transmission (both senses) of the data. need the baud rate to be given as argument void USARTn_Transmit (uint8_t) send 8 bits of data from the AT90CAN128. USARTn must be inizialized before uint8_t USARTn_Receive () receive 8 bits of data. int USARTnSendData(uint8_t *, uint8_t) this function asks for a pointer to a char array and a bitmask to the pin on which the devices are placed. Will store the Devices' ID numbers and the temperature they are reading on the array, and then will send all those datas through the USART register. The function returns the number of devices founded on the bus. 3.c) in the main are inizialized the following variables: br ate is the baud rate of the transmission regtemp is a char array in which are stored the devices IDs and the temperature they read. this data will be sent from the at90can128 usercommand is a char wich has to be received, the program will wait until some data is received on the USART pin after turning on the power and initializing the bus, the program will start an infinite loop (which terminates with a break_point) The program will wait until a command is received, and then a switch is setted: a) normal temp conversione is performed and data are sent away b) write new temperature limits (for alarm flag) on 1 device. while executing the program will wait for receiving the highest limit, the lowest limit and the ID number. several check point are issued to check the coherence of this data.A string is sent as result of the operation c) perform an alrm search and send the data away for any other case an error message is sent. 3)TEMPSENS2.C (definitve) tempsens2.c is a program which allows to read, after receiving a command on USART register, from several Dallas ds1820 devices the temperature and their 64 bits ID numbers, and send this datas on a serial port. Is possible to read from as many devices as wanted, placed on maximum 3 wires connected to pins 2,3,4 of jadc1 of HADSHOPOMO1. The serial transmission works properly at 4800 or 38400 baud (tested). 3.a) DS1820_START_CONVERSION here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start temperature conversion (see the ds1820 data sheet) DS1820_READ_SCRATCHPAD here is defined the protocol which the master has to send on the 1-wire bus in order to command the devices to start sending the data stored in the scratchpad memory (see the ds1820 data sheet) DS1820_WRITE_SCRATCHPAD here is defined the protocol which the master has to send on the 1-wire bus in order to be allowed to write on the devices' memory (see the ds1820 data sheet) DS1820_CONFIG_REGISTER here are deefined the standards settings for the register memory of the ds1820. NUM_DEVICES here is defined the maximum number of devices the user wants to read from. if there are more devices, the program will run properly but will only read from NUM_DEVICES devices. BAUD is the baud rate for the serial transmission. the formula for calculating the rigth value is given as comment. 3.b)break_point(int,uint8_t*) this function sets an interrumption in the program. to run needs to be given as argument an integer and a char pointer when the function break_point is reached, the program will stop running, and on the screen will appear a message with the code number of the break_point, given as argument, useful to know wich break_point had been reached, the value of the char pointer given as argument, the character or the string which the pointer is pointing uint16_t readtemperature(uint8_t, *uint8_t) this function will return the value of the temperature read by the sensor. It asks for a bitmask of the pin which the sensor is linked and for a pointer to an array of char of size 8 in which is stored the device ID. It returns a value inferior to -900 if an error occurs (for example the wanted devices is not connected to the given bus). the function will check the presence of the device (operation which also works as a reset pulse), then send the match_rom command which allows only the selected device to answer to the following command, and suddenly will ask the device to send the first 2 bytes of the scratchpad. the function will store them in the variable temperature and send a reset pulse again. for the functions used in ReadTemperature, see OWIHighLevelFunctions.c int TempStored(uint8_t * ) This function asks for an array (size)in which are stored the bitmask of the buses to scan. t is the variable in which the temperatures are stored before being sent away; IDS is a 2D array in which are stored all the ID's of the devices; countDEV is a counter for the number of devices countDEVbus is a counter for the number of devices on each bus onetemp[30] is the string which is sent away. It will scan all the buses for the presence of devices. For any bus on which are found devices, will store the ID's and, after, will send the CONVERT command to all the devices on the same bus at the sime time and wait for them to finish conversion. Before scanning the next bus, for every device will ask for the temperature, and will send its ID and its temperature away one character at time. At the end of the function a last end of string character is sent, so the receiver knows that the message is finished int AlarmStored(uint8_t ) this function works exactly in the same way of TempStored, but, as a different command is sent on the 1-wire bus, only those devices which are experiencing an alarm flag condition will be activated, and so only their temperature will be readen and only their data will be sent. void USARTn_Init (unsigned int) (note: n is 1 or 0) this function initialize the USARTn registers,in order to allow the transmission (both senses) of the data. need the baud rate to be given as argument. void USARTn_Transmit (uint8_t) send 8 bits of data from the AT90CAN128. USARTn must be inizialized before uint8_t USARTn_Receive () receive 8 bits of datas. USARTn must be inizialized before USART0_SendData() is no more used. For explanation of its working see previous versions. 3.c) in the main are inizialized the following variables: brate is the baud rate of the transmission usercommand is a char wich has to be received, the program will wait until some data is received on the USART pin BUSES is an array in which are stored the bitmasks of the buse on whhich is needed to perform the scan. It has to be of size 3. If less then 2 buses are connected, just put in the free pin number, the program will recognize that no devices are plugged in and will skip. The body of the main is in an infinite loop (which terminates with a break_point) The program will wait until a command is received, and then a switch is setted: a) normal temp conversion is performed and data are sent away. TESTED WITH 37 DEVICES ON 2 DIFFERENT BUSES; AT 38400 BAUD b) write new temperature limits (for alarm flag) on one device. while executing the program will wait for receiving the highest limit, the lowest limit and the ID number. several check point are issued to check the coherence of this data. A string is sent as result of the operation NOT TESTED c) perform an alarm search and send the data away for any other case an error message is sent. any other command, error message NOT TESTED 4) SERIALTRX.c 4.a) SLEEP_TIME every time that a readout is performed, the program will wait SLEEP_TIME seconds before readout again. BUFFSIZE is the size of the space allocated for reading the data of the devices. Must be at least NUMDEVICES*25+3. PROPER WORKING IS NOT ASSURED if BUFFSIZE IS NOT ENOUGH. 4.b) die end the execution of the program and print on a screen the message given as argument. IF IS WANTED THAT THE MESSAGE BEING PRINTED ON THE SERVER SCREEN, CHANGE perror(mess) INTO send(sock,mess,[mess size],0). PrintReceivedData(int fd, int sock) receives a string of data from the serial connection handled by fd. Then print it on the screen and send the same string through the socket handled by sock. IF WANTED, IT'S POSSIBLE TO NOT PRINT THE DATA ON THE LINUX PROCESSOR SCREEN JUST HIDDING LINE 98. int input_timeout(int fd,int s,int ms) waits for a maximum time of s.ms seconds or for some changes in the file handled by fd. Returns -1 if an error occurs, 0 if timeout is reached, 1 if data arrived to fd. 4.c) The first part of the main is initialization of socket and serial transmission. Then the program will enter in an endless loop will receive a command from the socket and forward it to the serila transmission. If the command is "b" will asks for needed information. Then will wait 5 seconds or for some data. If data arrives runs PrintReceivedData, if not prints on the screen (and send to the server) a "no data" message. Before starting an other loop, will wait for SLEEP_TIME seconds. Appendix A those programs need, for running of the following files, provided by ATMEL OWIHighLevelFunctions.c it contains the implementations of the functions OWI_Search_Rom, OWI_SendByte; OWY_ReceiveByte; OWI_MatchRom OWIHighLevelFunctions.h OWISWBitFunctions.c it contains the implementations of the functions OWI_Init and OWI_DetectPresence, plus other functions used in OWIHighLevelFunctions OWIBitFunctions.h OWIPolled.h it contains several definitions used in the programs. 21/9/2006, Giacomo Ortona