MAX31850, DS18B20, DS2450, thermocouple

Committer:
fblanc
Date:
Mon Mar 09 11:55:54 2015 +0000
Revision:
0:5d39f2521173
MAX31850

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fblanc 0:5d39f2521173 1 /**
fblanc 0:5d39f2521173 2 * @file DS2450.c
fblanc 0:5d39f2521173 3 * @brief library of DS2450 1-Wire Quad A/D Converter (http://www.maxim-ic.com/datasheet/index.mvp/id/2921)
fblanc 0:5d39f2521173 4 * @author Frederic BLANC (Published 01/03/2012 www.mbed.org)
fblanc 0:5d39f2521173 5 */
fblanc 0:5d39f2521173 6 #include "mbed.h"
fblanc 0:5d39f2521173 7 #include "onewire.h"
fblanc 0:5d39f2521173 8 #include "DS2450.h"
fblanc 0:5d39f2521173 9 #include "crc8.h"
fblanc 0:5d39f2521173 10 #include "crc16.h"
fblanc 0:5d39f2521173 11 #include "utils.h"
fblanc 0:5d39f2521173 12 //**********************************************************************************************************
fblanc 0:5d39f2521173 13 //* DS2450_read_ADC
fblanc 0:5d39f2521173 14 //**********************************************************************************************************
fblanc 0:5d39f2521173 15
fblanc 0:5d39f2521173 16 /**
fblanc 0:5d39f2521173 17 * @brief lancement lecture DS2450 ADC
fblanc 0:5d39f2521173 18 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 19 * @param [out] adc[] tableau des valeurs des adc
fblanc 0:5d39f2521173 20 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 21 * @date 20/06/2011
fblanc 0:5d39f2521173 22 *
fblanc 0:5d39f2521173 23 */
fblanc 0:5d39f2521173 24 uint8_t DS2450_read_ADC(uint8_t id[], uint16_t adc[]) {
fblanc 0:5d39f2521173 25 uint8_t i,j;
fblanc 0:5d39f2521173 26 uint8_t error;
fblanc 0:5d39f2521173 27 uint8_t sp[DS2450_SP_SIZE];
fblanc 0:5d39f2521173 28 //waiting for convertion time ( nbchannel x resolution x 80�s +160�s)
fblanc 0:5d39f2521173 29
fblanc 0:5d39f2521173 30 error=DS2450_read_page(&id[0],DS2450_PAGE0,&sp[0]); //read data
fblanc 0:5d39f2521173 31 if (error)
fblanc 0:5d39f2521173 32 return error;
fblanc 0:5d39f2521173 33 j=0;
fblanc 0:5d39f2521173 34 for (i=0;i<8;i+=2)
fblanc 0:5d39f2521173 35 adc[j++]=uint8_to_uint16(sp[i+3],sp[i+4]); //sp[i+3] LSB ,sp[i+4] MSB
fblanc 0:5d39f2521173 36 return OW_OK;
fblanc 0:5d39f2521173 37 }
fblanc 0:5d39f2521173 38
fblanc 0:5d39f2521173 39
fblanc 0:5d39f2521173 40 /**
fblanc 0:5d39f2521173 41 * @brief lancement lecture DS2450 ADC
fblanc 0:5d39f2521173 42 * @param [in] n num bus onewire
fblanc 0:5d39f2521173 43 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 44 * @param [out] adc[] tableau des valeurs des adc
fblanc 0:5d39f2521173 45 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 46 * @date 07/09/2011
fblanc 0:5d39f2521173 47 *
fblanc 0:5d39f2521173 48 */
fblanc 0:5d39f2521173 49 uint8_t DS2450_read_ADC(uint8_t n,uint8_t id[], uint16_t adc[]) {
fblanc 0:5d39f2521173 50 uint8_t i,j;
fblanc 0:5d39f2521173 51 uint8_t error;
fblanc 0:5d39f2521173 52 uint8_t sp[DS2450_SP_SIZE];
fblanc 0:5d39f2521173 53 //waiting for convertion time ( nbchannel x resolution x 80&#65533;s +160&#65533;s)
fblanc 0:5d39f2521173 54
fblanc 0:5d39f2521173 55 error=DS2450_read_page(n,&id[0],DS2450_PAGE0,&sp[0]); //read data
fblanc 0:5d39f2521173 56 if (error)
fblanc 0:5d39f2521173 57 return error;
fblanc 0:5d39f2521173 58 j=0;
fblanc 0:5d39f2521173 59 for (i=0;i<8;i+=2)
fblanc 0:5d39f2521173 60 adc[j++]=uint8_to_uint16(sp[i+3],sp[i+4]); //sp[i+3] LSB ,sp[i+4] MSB
fblanc 0:5d39f2521173 61 return OW_OK;
fblanc 0:5d39f2521173 62 }
fblanc 0:5d39f2521173 63 //**********************************************************************************************************
fblanc 0:5d39f2521173 64 //* DS2450_start_and_read_ADC
fblanc 0:5d39f2521173 65 //**********************************************************************************************************
fblanc 0:5d39f2521173 66
fblanc 0:5d39f2521173 67 /**
fblanc 0:5d39f2521173 68 * @brief lancement & lecture DS2450 ADC
fblanc 0:5d39f2521173 69 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 70 * @param [out] adc[] tableau des valeurs des adc
fblanc 0:5d39f2521173 71 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 72 * @date 20/06/2011
fblanc 0:5d39f2521173 73 *
fblanc 0:5d39f2521173 74 */
fblanc 0:5d39f2521173 75 uint8_t DS2450_start_and_read_ADC(uint8_t id[], uint16_t adc[]) {
fblanc 0:5d39f2521173 76 uint8_t i,j;
fblanc 0:5d39f2521173 77 uint8_t error;
fblanc 0:5d39f2521173 78 uint8_t sp[DS2450_SP_SIZE];
fblanc 0:5d39f2521173 79
fblanc 0:5d39f2521173 80 error=DS2450_convert(&id[0],0x0F,0x00); //start convert
fblanc 0:5d39f2521173 81 if (error)
fblanc 0:5d39f2521173 82 return error;
fblanc 0:5d39f2521173 83
fblanc 0:5d39f2521173 84 wait_ms(15); //waiting for convertion time ( nbchannel x resolution x 80&#65533;s +160&#65533;s)
fblanc 0:5d39f2521173 85
fblanc 0:5d39f2521173 86 error=DS2450_read_page(&id[0],DS2450_PAGE0,&sp[0]); //read data
fblanc 0:5d39f2521173 87 if (error)
fblanc 0:5d39f2521173 88 return error;
fblanc 0:5d39f2521173 89
fblanc 0:5d39f2521173 90 j=0;
fblanc 0:5d39f2521173 91 for (i=0;i<8;i+=2)
fblanc 0:5d39f2521173 92 adc[j++]=uint8_to_uint16(sp[i+3],sp[i+4]); //sp[i+3] LSB ,sp[i+4] MSB
fblanc 0:5d39f2521173 93 return OW_OK;
fblanc 0:5d39f2521173 94 }
fblanc 0:5d39f2521173 95
fblanc 0:5d39f2521173 96 /**
fblanc 0:5d39f2521173 97 * @brief lancement & lecture DS2450 ADC
fblanc 0:5d39f2521173 98 * @param [in] n num bus onewire
fblanc 0:5d39f2521173 99 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 100 * @param [out] adc[] tableau des valeurs des adc
fblanc 0:5d39f2521173 101 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 102 * @date 07/09/2011
fblanc 0:5d39f2521173 103 *
fblanc 0:5d39f2521173 104 */
fblanc 0:5d39f2521173 105 uint8_t DS2450_start_and_read_ADC(uint8_t n,uint8_t id[], uint16_t adc[]) {
fblanc 0:5d39f2521173 106 uint8_t i,j;
fblanc 0:5d39f2521173 107 uint8_t error;
fblanc 0:5d39f2521173 108 uint8_t sp[DS2450_SP_SIZE];
fblanc 0:5d39f2521173 109
fblanc 0:5d39f2521173 110 error=DS2450_convert(n,&id[0],0x0F,0x00); //start convert
fblanc 0:5d39f2521173 111 if (error)
fblanc 0:5d39f2521173 112 return error;
fblanc 0:5d39f2521173 113
fblanc 0:5d39f2521173 114 wait_ms(15); //waiting for convertion time ( nbchannel x resolution x 80&#65533;s +160&#65533;s)
fblanc 0:5d39f2521173 115
fblanc 0:5d39f2521173 116 error=DS2450_read_page(n,&id[0],DS2450_PAGE0,&sp[0]); //read data
fblanc 0:5d39f2521173 117 if (error)
fblanc 0:5d39f2521173 118 return error;
fblanc 0:5d39f2521173 119
fblanc 0:5d39f2521173 120 j=0;
fblanc 0:5d39f2521173 121 for (i=0;i<8;i+=2)
fblanc 0:5d39f2521173 122 adc[j++]=uint8_to_uint16(sp[i+3],sp[i+4]); //sp[i+3] LSB ,sp[i+4] MSB
fblanc 0:5d39f2521173 123 return OW_OK;
fblanc 0:5d39f2521173 124 }
fblanc 0:5d39f2521173 125
fblanc 0:5d39f2521173 126 //**********************************************************************************************************
fblanc 0:5d39f2521173 127 //* DS2450_read_page
fblanc 0:5d39f2521173 128 //**********************************************************************************************************
fblanc 0:5d39f2521173 129
fblanc 0:5d39f2521173 130 /**
fblanc 0:5d39f2521173 131 * @brief lancement lecture page DS2450 ADC
fblanc 0:5d39f2521173 132 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 133 * @param [in] adresse de la page a lire
fblanc 0:5d39f2521173 134 * @param [out] uint16_t sp tableau des valeurs de la page
fblanc 0:5d39f2521173 135 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 136 * @date 20/06/2011
fblanc 0:5d39f2521173 137 *
fblanc 0:5d39f2521173 138 */
fblanc 0:5d39f2521173 139 uint8_t DS2450_read_page(uint8_t id[], uint8_t adresse,
fblanc 0:5d39f2521173 140 uint8_t *sp) {
fblanc 0:5d39f2521173 141 uint8_t i;
fblanc 0:5d39f2521173 142 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 143 if (ow_reset()) //reset OW
fblanc 0:5d39f2521173 144 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 145 sp[0]=DS2450_READ_MEMORY; // command
fblanc 0:5d39f2521173 146 sp[1]=adresse; //adress page LSB
fblanc 0:5d39f2521173 147 sp[2]=0; //adress page MSB
fblanc 0:5d39f2521173 148 ow_command(sp[0], &id[0]);
fblanc 0:5d39f2521173 149 ow_byte_wr(sp[1]);
fblanc 0:5d39f2521173 150 ow_byte_wr(sp[2]);
fblanc 0:5d39f2521173 151
fblanc 0:5d39f2521173 152 for ( i=3 ; i< DS2450_SP_SIZE; i++ ) { //read 8xdata + CRC16
fblanc 0:5d39f2521173 153 sp[i]=ow_byte_rd();
fblanc 0:5d39f2521173 154 }
fblanc 0:5d39f2521173 155
fblanc 0:5d39f2521173 156 if (ctrl_crc16( &sp[0], DS2450_SP_SIZE ) ) { //CRC16 (command+adress page LSB+adress page MSB+8xdata)
fblanc 0:5d39f2521173 157 wait_ms(100); //wait 100ms if error
fblanc 0:5d39f2521173 158 if ((sp[DS2450_SP_SIZE-1]==0xFF) && (sp[DS2450_SP_SIZE-2]==0xFF))
fblanc 0:5d39f2521173 159 return OW_ERROR; // bus error
fblanc 0:5d39f2521173 160 if ((sp[DS2450_SP_SIZE-1]==0x00) && (sp[DS2450_SP_SIZE-2]==0x00))
fblanc 0:5d39f2521173 161 return OW_BUSY;
fblanc 0:5d39f2521173 162
fblanc 0:5d39f2521173 163 return OW_ERROR_CRC; // data error
fblanc 0:5d39f2521173 164 }
fblanc 0:5d39f2521173 165 return OW_OK;
fblanc 0:5d39f2521173 166 }
fblanc 0:5d39f2521173 167 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 168 }
fblanc 0:5d39f2521173 169 /**
fblanc 0:5d39f2521173 170 * @brief lancement lecture page DS2450 ADC
fblanc 0:5d39f2521173 171 * @param [in] n num bus onewire
fblanc 0:5d39f2521173 172 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 173 * @param [in] adresse de la page a lire
fblanc 0:5d39f2521173 174 * @param [out] sp tableau des valeurs de la page
fblanc 0:5d39f2521173 175 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 176 * @date 07/09/2011
fblanc 0:5d39f2521173 177 *
fblanc 0:5d39f2521173 178 */
fblanc 0:5d39f2521173 179 uint8_t DS2450_read_page(uint8_t n,uint8_t id[], uint8_t adresse,
fblanc 0:5d39f2521173 180 uint8_t *sp) {
fblanc 0:5d39f2521173 181 uint8_t i;
fblanc 0:5d39f2521173 182 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 183 if (ow_reset(n)) //reset OW
fblanc 0:5d39f2521173 184 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 185 sp[0]=DS2450_READ_MEMORY; // command
fblanc 0:5d39f2521173 186 sp[1]=adresse; //adress page LSB
fblanc 0:5d39f2521173 187 sp[2]=0; //adress page MSB
fblanc 0:5d39f2521173 188 ow_command(n,sp[0], &id[0]);
fblanc 0:5d39f2521173 189 ow_byte_wr(n,sp[1]);
fblanc 0:5d39f2521173 190 ow_byte_wr(n,sp[2]);
fblanc 0:5d39f2521173 191
fblanc 0:5d39f2521173 192 for ( i=3 ; i< DS2450_SP_SIZE; i++ ) { //read 8xdata + CRC16
fblanc 0:5d39f2521173 193 sp[i]=ow_byte_rd(n);
fblanc 0:5d39f2521173 194 }
fblanc 0:5d39f2521173 195
fblanc 0:5d39f2521173 196 if (ctrl_crc16( &sp[0], DS2450_SP_SIZE ) ) { //CRC16 (command+adress page LSB+adress page MSB+8xdata)
fblanc 0:5d39f2521173 197 wait_ms(100); //wait 100ms if error
fblanc 0:5d39f2521173 198 if ((sp[DS2450_SP_SIZE-1]==0xFF) && (sp[DS2450_SP_SIZE-2]==0xFF))
fblanc 0:5d39f2521173 199 return OW_ERROR; // bus error
fblanc 0:5d39f2521173 200 if ((sp[DS2450_SP_SIZE-1]==0x00) && (sp[DS2450_SP_SIZE-2]==0x00))
fblanc 0:5d39f2521173 201 return OW_BUSY;
fblanc 0:5d39f2521173 202
fblanc 0:5d39f2521173 203 return OW_ERROR_CRC; // data error
fblanc 0:5d39f2521173 204 }
fblanc 0:5d39f2521173 205 return OW_OK;
fblanc 0:5d39f2521173 206 }
fblanc 0:5d39f2521173 207 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 208 }
fblanc 0:5d39f2521173 209 //**********************************************************************************************************
fblanc 0:5d39f2521173 210 //* DS2450_convert
fblanc 0:5d39f2521173 211 //**********************************************************************************************************
fblanc 0:5d39f2521173 212
fblanc 0:5d39f2521173 213 /**
fblanc 0:5d39f2521173 214 * @brief lancement convertion DS2450 ADC
fblanc 0:5d39f2521173 215 * @param [in] uint8_t id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 216 * @param [in] uint8_t input_select_mask
fblanc 0:5d39f2521173 217 * @param [in] uint8_t read_out_control
fblanc 0:5d39f2521173 218 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 219 * @date 20/06/2011
fblanc 0:5d39f2521173 220 *
fblanc 0:5d39f2521173 221 */
fblanc 0:5d39f2521173 222 uint8_t DS2450_convert(uint8_t id[], uint8_t input_select_mask,uint8_t read_out_control) {
fblanc 0:5d39f2521173 223 uint8_t i;
fblanc 0:5d39f2521173 224 uint8_t sp[5];
fblanc 0:5d39f2521173 225 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 226 if (ow_reset()) //reset OW
fblanc 0:5d39f2521173 227 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 228 sp[0]=DS2450_CONVERT; // command
fblanc 0:5d39f2521173 229 sp[1]=input_select_mask; //mask
fblanc 0:5d39f2521173 230 sp[2]=read_out_control; //control
fblanc 0:5d39f2521173 231 ow_command(sp[0], &id[0]);
fblanc 0:5d39f2521173 232 ow_byte_wr(sp[1]);
fblanc 0:5d39f2521173 233 ow_byte_wr(sp[2]);
fblanc 0:5d39f2521173 234 for ( i=3 ; i< 5; i++ ) { // read CRC16
fblanc 0:5d39f2521173 235 sp[i]=ow_byte_rd();
fblanc 0:5d39f2521173 236 }
fblanc 0:5d39f2521173 237
fblanc 0:5d39f2521173 238 if (ctrl_crc16( &sp[0], 5 ) ) { //CRC16 (command+mask LSB+control)
fblanc 0:5d39f2521173 239 if ((sp[3]==0xFF) && (sp[3]==0xFF))
fblanc 0:5d39f2521173 240 return OW_ERROR;
fblanc 0:5d39f2521173 241 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 242 }
fblanc 0:5d39f2521173 243 return OW_OK;
fblanc 0:5d39f2521173 244 }
fblanc 0:5d39f2521173 245 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 246 }
fblanc 0:5d39f2521173 247 /**
fblanc 0:5d39f2521173 248 * @brief lancement convertion DS2450 ADC
fblanc 0:5d39f2521173 249 * @param [in] n num bus onewire
fblanc 0:5d39f2521173 250 * @param [in] uint8_t id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 251 * @param [in] uint8_t input_select_mask
fblanc 0:5d39f2521173 252 * @param [in] uint8_t read_out_control
fblanc 0:5d39f2521173 253 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 254 * @date 07/09/2011
fblanc 0:5d39f2521173 255 *
fblanc 0:5d39f2521173 256 */
fblanc 0:5d39f2521173 257 uint8_t DS2450_convert(uint8_t n,uint8_t id[], uint8_t input_select_mask,uint8_t read_out_control) {
fblanc 0:5d39f2521173 258 uint8_t i;
fblanc 0:5d39f2521173 259 uint8_t sp[5];
fblanc 0:5d39f2521173 260 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 261 if (ow_reset(n)) //reset OW
fblanc 0:5d39f2521173 262 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 263 sp[0]=DS2450_CONVERT; // command
fblanc 0:5d39f2521173 264 sp[1]=input_select_mask; //mask
fblanc 0:5d39f2521173 265 sp[2]=read_out_control; //control
fblanc 0:5d39f2521173 266 ow_command(n,sp[0], &id[0]);
fblanc 0:5d39f2521173 267 ow_byte_wr(n,sp[1]);
fblanc 0:5d39f2521173 268 ow_byte_wr(n,sp[2]);
fblanc 0:5d39f2521173 269 for ( i=3 ; i< 5; i++ ) { // read CRC16
fblanc 0:5d39f2521173 270 sp[i]=ow_byte_rd(n);
fblanc 0:5d39f2521173 271 }
fblanc 0:5d39f2521173 272
fblanc 0:5d39f2521173 273 if (ctrl_crc16( &sp[0], 5 ) ) { //CRC16 (command+mask LSB+control)
fblanc 0:5d39f2521173 274 if ((sp[3]==0xFF) && (sp[3]==0xFF))
fblanc 0:5d39f2521173 275 return OW_ERROR;
fblanc 0:5d39f2521173 276 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 277 }
fblanc 0:5d39f2521173 278 return OW_OK;
fblanc 0:5d39f2521173 279 }
fblanc 0:5d39f2521173 280 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 281 }
fblanc 0:5d39f2521173 282
fblanc 0:5d39f2521173 283 //**********************************************************************************************************
fblanc 0:5d39f2521173 284 //* DS2450_configure_channel_ADC
fblanc 0:5d39f2521173 285 //**********************************************************************************************************
fblanc 0:5d39f2521173 286
fblanc 0:5d39f2521173 287 /**
fblanc 0:5d39f2521173 288 * @brief configure canal ADC DS2450
fblanc 0:5d39f2521173 289 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 290 * @param [in] channel
fblanc 0:5d39f2521173 291 * @param [in] conflsb configuration OE-A OC-A 0 0 RC3-A RC2-A RC1-A RC0-A
fblanc 0:5d39f2521173 292 * @param [in] confmsb configuration POR 0 AFH-A AFL-A AEH-A AEL-A 0 IR-A
fblanc 0:5d39f2521173 293 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 294 * @date 20/06/2011
fblanc 0:5d39f2521173 295 *
fblanc 0:5d39f2521173 296 */
fblanc 0:5d39f2521173 297 uint8_t DS2450_configure_channel_ADC(uint8_t id[],uint8_t channel,uint8_t conflsb,uint8_t confmsb) {
fblanc 0:5d39f2521173 298 uint8_t i;
fblanc 0:5d39f2521173 299 uint8_t sp[7];
fblanc 0:5d39f2521173 300 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 301 if (ow_reset()) //reset OW
fblanc 0:5d39f2521173 302 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 303 sp[0]=DS2450_WRITE_MEMORY; // command
fblanc 0:5d39f2521173 304 sp[1]=DS2450_PAGE1+channel; //adress page LSB
fblanc 0:5d39f2521173 305 sp[2]=0x00; //adress page MSB
fblanc 0:5d39f2521173 306 sp[3]=conflsb; //databyte
fblanc 0:5d39f2521173 307 ow_command(sp[0], &id[0]);
fblanc 0:5d39f2521173 308 ow_byte_wr(sp[1]);
fblanc 0:5d39f2521173 309 ow_byte_wr(sp[2]);
fblanc 0:5d39f2521173 310 ow_byte_wr(sp[3]);
fblanc 0:5d39f2521173 311 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 312 sp[i]=ow_byte_rd();
fblanc 0:5d39f2521173 313 }
fblanc 0:5d39f2521173 314
fblanc 0:5d39f2521173 315 if (ctrl_crc16( &sp[0], 6 ) ) //CRC16 (command+adress page LSB+adress page MSB+databyte)
fblanc 0:5d39f2521173 316 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 317 sp[3]=confmsb; //databyte
fblanc 0:5d39f2521173 318 ow_byte_wr(sp[3]);
fblanc 0:5d39f2521173 319 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 320 sp[i]=ow_byte_rd();
fblanc 0:5d39f2521173 321 }
fblanc 0:5d39f2521173 322
fblanc 0:5d39f2521173 323 if (sp[3]!=sp[6] ) //control data
fblanc 0:5d39f2521173 324 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 325 return OW_OK;
fblanc 0:5d39f2521173 326 }
fblanc 0:5d39f2521173 327 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 328 }
fblanc 0:5d39f2521173 329 /**
fblanc 0:5d39f2521173 330 * @brief configure canal ADC DS2450
fblanc 0:5d39f2521173 331 * @param [in] n num bus onewire
fblanc 0:5d39f2521173 332 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 333 * @param [in] channel
fblanc 0:5d39f2521173 334 * @param [in] conflsb configuration OE-A OC-A 0 0 RC3-A RC2-A RC1-A RC0-A
fblanc 0:5d39f2521173 335 * @param [in] confmsb configuration POR 0 AFH-A AFL-A AEH-A AEL-A 0 IR-A
fblanc 0:5d39f2521173 336 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 337 * @date 20/06/2011
fblanc 0:5d39f2521173 338 *
fblanc 0:5d39f2521173 339 */
fblanc 0:5d39f2521173 340 uint8_t DS2450_configure_channel_ADC(uint8_t n,uint8_t id[],uint8_t channel,uint8_t conflsb,uint8_t confmsb) {
fblanc 0:5d39f2521173 341 uint8_t i;
fblanc 0:5d39f2521173 342 uint8_t sp[7];
fblanc 0:5d39f2521173 343 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 344 if (ow_reset(n)) //reset OW
fblanc 0:5d39f2521173 345 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 346 sp[0]=DS2450_WRITE_MEMORY; // command
fblanc 0:5d39f2521173 347 sp[1]=DS2450_PAGE1+channel; //adress page LSB
fblanc 0:5d39f2521173 348 sp[2]=0x00; //adress page MSB
fblanc 0:5d39f2521173 349 sp[3]=conflsb; //databyte
fblanc 0:5d39f2521173 350 ow_command(n,sp[0], &id[0]);
fblanc 0:5d39f2521173 351 ow_byte_wr(n,sp[1]);
fblanc 0:5d39f2521173 352 ow_byte_wr(n,sp[2]);
fblanc 0:5d39f2521173 353 ow_byte_wr(n,sp[3]);
fblanc 0:5d39f2521173 354 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 355 sp[i]=ow_byte_rd(n);
fblanc 0:5d39f2521173 356 }
fblanc 0:5d39f2521173 357
fblanc 0:5d39f2521173 358 if (ctrl_crc16( &sp[0], 6 ) ) //CRC16 (command+adress page LSB+adress page MSB+databyte)
fblanc 0:5d39f2521173 359 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 360 sp[3]=confmsb; //databyte
fblanc 0:5d39f2521173 361 ow_byte_wr(n,sp[3]);
fblanc 0:5d39f2521173 362 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 363 sp[i]=ow_byte_rd(n);
fblanc 0:5d39f2521173 364 }
fblanc 0:5d39f2521173 365
fblanc 0:5d39f2521173 366 if (sp[3]!=sp[6] ) //control data
fblanc 0:5d39f2521173 367 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 368 return OW_OK;
fblanc 0:5d39f2521173 369 }
fblanc 0:5d39f2521173 370 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 371 }
fblanc 0:5d39f2521173 372 //**********************************************************************************************************
fblanc 0:5d39f2521173 373 //* DS2450_configure_channel_ADC
fblanc 0:5d39f2521173 374 //**********************************************************************************************************
fblanc 0:5d39f2521173 375
fblanc 0:5d39f2521173 376 /**
fblanc 0:5d39f2521173 377 * @brief configure PAGE
fblanc 0:5d39f2521173 378 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 379 * @param [in] uint8_t adresse de la page a ecrire
fblanc 0:5d39f2521173 380 * @param [in] config_page tableau de 8 byte
fblanc 0:5d39f2521173 381 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 382 * @date 20/06/2011
fblanc 0:5d39f2521173 383 *
fblanc 0:5d39f2521173 384 */
fblanc 0:5d39f2521173 385 uint8_t DS2450_configure_page(uint8_t id[], uint8_t adresse,uint8_t configpage[]) {
fblanc 0:5d39f2521173 386 uint8_t i,j;
fblanc 0:5d39f2521173 387 uint8_t sp[7];
fblanc 0:5d39f2521173 388 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 389 if (ow_reset()) //reset OW
fblanc 0:5d39f2521173 390 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 391 sp[0]=DS2450_WRITE_MEMORY; // command
fblanc 0:5d39f2521173 392 sp[1]=adresse; //adress page LSB
fblanc 0:5d39f2521173 393 sp[2]=0x00; //adress page MSB
fblanc 0:5d39f2521173 394 sp[3]=configpage[0]; //databyte
fblanc 0:5d39f2521173 395 ow_command(sp[0], &id[0]);
fblanc 0:5d39f2521173 396 ow_byte_wr(sp[1]);
fblanc 0:5d39f2521173 397 ow_byte_wr(sp[2]);
fblanc 0:5d39f2521173 398 ow_byte_wr(sp[3]);
fblanc 0:5d39f2521173 399 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 400 sp[i]=ow_byte_rd();
fblanc 0:5d39f2521173 401 }
fblanc 0:5d39f2521173 402
fblanc 0:5d39f2521173 403 if (sp[3]!=sp[6] ) //control data
fblanc 0:5d39f2521173 404 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 405
fblanc 0:5d39f2521173 406 for ( j=1 ; j< 7; j++ ) {
fblanc 0:5d39f2521173 407 sp[3]=configpage[j]; //databyte
fblanc 0:5d39f2521173 408 ow_byte_wr(sp[3]);
fblanc 0:5d39f2521173 409 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 410 sp[i]=ow_byte_rd();
fblanc 0:5d39f2521173 411 }
fblanc 0:5d39f2521173 412 if (sp[3]!=sp[6] ) //control data
fblanc 0:5d39f2521173 413 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 414
fblanc 0:5d39f2521173 415 }
fblanc 0:5d39f2521173 416 return OW_OK;
fblanc 0:5d39f2521173 417 }
fblanc 0:5d39f2521173 418 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 419 }
fblanc 0:5d39f2521173 420 /**
fblanc 0:5d39f2521173 421 * @brief configure PAGE
fblanc 0:5d39f2521173 422 * @param [in] n num bus onewire
fblanc 0:5d39f2521173 423 * @param [in] id[] tableau d'identifiant OW
fblanc 0:5d39f2521173 424 * @param [in] uint8_t adresse de la page a ecrire
fblanc 0:5d39f2521173 425 * @param [in] config_page tableau de 8 byte
fblanc 0:5d39f2521173 426 * @return OW_OK si erreur retourne OW_ERROR_CRC
fblanc 0:5d39f2521173 427 * @date 07/09/2011
fblanc 0:5d39f2521173 428 *
fblanc 0:5d39f2521173 429 */
fblanc 0:5d39f2521173 430 uint8_t DS2450_configure_page(uint8_t n,uint8_t id[], uint8_t adresse,uint8_t configpage[]) {
fblanc 0:5d39f2521173 431 uint8_t i,j;
fblanc 0:5d39f2521173 432 uint8_t sp[7];
fblanc 0:5d39f2521173 433 if (id[0] == DS2450_ID) {
fblanc 0:5d39f2521173 434 if (ow_reset(n)) //reset OW
fblanc 0:5d39f2521173 435 return OW_SHORT_CIRCUIT;
fblanc 0:5d39f2521173 436 sp[0]=DS2450_WRITE_MEMORY; // command
fblanc 0:5d39f2521173 437 sp[1]=adresse; //adress page LSB
fblanc 0:5d39f2521173 438 sp[2]=0x00; //adress page MSB
fblanc 0:5d39f2521173 439 sp[3]=configpage[0]; //databyte
fblanc 0:5d39f2521173 440 ow_command(n,sp[0], &id[0]);
fblanc 0:5d39f2521173 441 ow_byte_wr(n,sp[1]);
fblanc 0:5d39f2521173 442 ow_byte_wr(n,sp[2]);
fblanc 0:5d39f2521173 443 ow_byte_wr(n,sp[3]);
fblanc 0:5d39f2521173 444 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 445 sp[i]=ow_byte_rd(n);
fblanc 0:5d39f2521173 446 }
fblanc 0:5d39f2521173 447
fblanc 0:5d39f2521173 448 if (sp[3]!=sp[6] ) //control data
fblanc 0:5d39f2521173 449 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 450
fblanc 0:5d39f2521173 451 for ( j=1 ; j< 7; j++ ) {
fblanc 0:5d39f2521173 452 sp[3]=configpage[j]; //databyte
fblanc 0:5d39f2521173 453 ow_byte_wr(n,sp[3]);
fblanc 0:5d39f2521173 454 for ( i=4 ; i< 7; i++ ) { //read CRC16+databyte
fblanc 0:5d39f2521173 455 sp[i]=ow_byte_rd(n);
fblanc 0:5d39f2521173 456 }
fblanc 0:5d39f2521173 457 if (sp[3]!=sp[6] ) //control data
fblanc 0:5d39f2521173 458 return OW_ERROR_CRC;
fblanc 0:5d39f2521173 459
fblanc 0:5d39f2521173 460 }
fblanc 0:5d39f2521173 461 return OW_OK;
fblanc 0:5d39f2521173 462 }
fblanc 0:5d39f2521173 463 return OW_ERROR_BAD_ID;
fblanc 0:5d39f2521173 464 }