OneWire DS18B20,DS2450,MAX31850

Dependents:   MAX31850_HelloWorld

Committer:
fblanc
Date:
Thu Feb 12 14:03:55 2015 +0000
Revision:
0:9acbbb021a43
MAX31850 ok

Who changed what in which revision?

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