CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
I2C_termometro.c
Go to the documentation of this file.
1
2
3#include "tutti_gli_header.h"
4
5// DOCUMENTAZIONE DOXYGEN
6
7/// \file
8
9/*! \page Thermometer
10*\brief <span style="color:red;"> <b> Managing of the thermometer on preamplifiers </b> </span>
11*\tableofcontents
12
13 \b SUMMARY:
14*\arg \ref thermometer_readout
15*\arg \ref thermometer_sw
16
17*\section thermometer_readout User use of thermometer on preamplifiers
18<hr width="75%" size="10" align="left">
19
20\n The thermometer is the <a href="./File_pdf/lm73.pdf" target=_blank><b>LM73</b></a> tha has a 14-bits digital ouput via I2C bus. Its schematic is
21in figure \ref Figure_I2C_mux. It has been developed one function ofr its managing: termometro_lettura() with input parameters: <i> uint8_t scheda_su_scheda_giu, uint8_t canale, uint32_t *temperatura_in_microK </i>,
22 the ouput is the pointer to \b temperatura_in_microK
23
24 <span style="color:orange;"> <I>
25\code {.c}
26uint32_t temperatura_in_microK;
27termometro_lettura( scheda_su_scheda_giu_provvisorio, canale_ , &temperatura_in_microK )
28\endcode
29</I> </span>
30
31*\anchor Figure_I2C_mux
32*\image html LM73_scheme.png "FigureLM73 1: LM73 scheme" width=40%
33*\image latex LM73_scheme.png "FigureLM73 1: LM73 scheme" width=40%
34
35*\section thermometer_sw Thermometer function
36<hr width="75%" size="10" align="left">
37\n Thermometrs are sent into shut down mode at the startup by means of termometro_sht_down( uint8_t scheda_su_scheda_giu, uint8_t canale ).
38\n Here is the reading thermometer function termometro_lettura():
39\snippetlineno I2C_termometro.c fun_termometro_lettura
40
41\n The selction of the thermometr needs 2 parameters: the I2C and its I2C address. These parameters are found in the const strucure #termometro_adrress[6].
42\n The I2C addresses are:
43- #termometro_I2C_Address_pari
44- #termometro_I2C_Address_dispari.
45
46\n The codes for mamnaging the trimmer are:
47 - \ref I2C_termometro.c
48 - \ref I2C_termometro.h
49
50<!-- pappa -->
51*/
52
53
54//INIZIO CROSS
55/*!\brief Thermometer selection structure
56*/
58// uint8_t quale_I2C;
59// uint8_t indirizzo_I2C
65 I2C_mux_abilita_2,termometro_I2C_Address_dispari }; //< Address of the memoies onboard, this is a 16k bits
66
67
68 /*! \brief Read the termometer on preamplifier
69
70*\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
71*\param[in] canale the channel of the mux to be enabled
72*\param[out] *temperatura_in_microK pointer to the temperature to read.
73*\return No Parameters
74\showrefby
75\showrefs
76\snippetlineno I2C_termometro.c fun_termometro_lettura
77*/
78 //! <!-- [fun_termometro_lettura] -->
79void termometro_lettura( uint8_t scheda_su_scheda_giu, uint8_t canale, uint32_t *temperatura_in_microK ){
80
81 //< registri termometro
82 #define reg_temperatura 0
83 #define reg_configuration 1
84 #define reg_control_status 4
85 //< Commands
86 #define Shut_down_and_one_shot_command_for_config_reg 0x84
87 #define Max_accuracy_command_for_control_reg 0x60
88 #define maschera_DAV 1
89
90 uint8_t comando1[]={reg_control_status,Max_accuracy_command_for_control_reg};
91 uint8_t comando2[]={reg_configuration, Shut_down_and_one_shot_command_for_config_reg};
92// uint8_t comando2[]={reg_configuration, 0};
93 uint8_t comando3[]={reg_temperatura};
94 uint8_t comando4[]={reg_control_status};
95 uint8_t lettura[2];
96
97
98//void I2C_mux_select_ch( uint8_t scheda_su_scheda_giu, I2C_mainboard,uint8_t canale_da_abilitare)
99 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, termometro_adrress[canale].quale_I2C);
100
101 I2C_mux -> MasterTransmit( termometro_adrress[canale].indirizzo_I2C, comando1, 2,false); //bestacuracy
102 while( I2C_mux -> GetStatus().busy); // White transmission complete
104 I2C_mux -> MasterTransmit( termometro_adrress[canale].indirizzo_I2C, comando2, 2,false); //onseshot meas
105 while( I2C_mux -> GetStatus().busy); // White transmission complete
106 Aspetta_tanti_ms(150);
108
109 lettura[0]=0;
110 uint8_t conta_err=0;
111 while( ((lettura[0] & maschera_DAV) == 0) && (conta_err<10) ){
112 I2C_mux -> MasterTransmit( termometro_adrress[canale].indirizzo_I2C, comando4 , 1,false); //lettura control reg per dato pronto
113 while( I2C_mux -> GetStatus().busy); // White transmission complete
115
116 I2C_mux -> MasterReceive( termometro_adrress[canale].indirizzo_I2C, lettura, 2,false); //Read back the temperature
117 while( I2C_mux -> GetStatus().busy);
118 conta_err ++;
119 }
120 if(conta_err >=10) ERROR_codifica_errore(scheda_su_scheda_giu ,error_address_I2C0_B , I2C_error_termometro_0 + canale, 1);
121
122 I2C_mux -> MasterTransmit( termometro_adrress[canale].indirizzo_I2C, comando3, 1,false); //read temperature
123 while( I2C_mux -> GetStatus().busy); // White transmission complete
125
126 I2C_mux -> MasterReceive( termometro_adrress[canale].indirizzo_I2C, lettura, 2,false); //Read back the temperature
127 while( I2C_mux -> GetStatus().busy);
128
129 *temperatura_in_microK = ((uint32_t)lettura[0] <<8 ) + (uint32_t) lettura[1] ;
130 *temperatura_in_microK = *temperatura_in_microK & 0x7FFF ;
131 *temperatura_in_microK = (*temperatura_in_microK >> 2 ) *31250; //Resilt in microK
132
133 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, I2C_mux_disabilita_tutto);
134
135}
136//! <!-- [fun_termometro_lettura] -->
137
138 /*! \brief Thermometer in shtdown
139
140*\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
141*\param[in] canale the channel of the mux to be enabled
142*\return No Parameters
143\showrefby
144\showrefs
145\snippetlineno I2C_termometro.c fun_termometro_sht_down
146*/
147 //! <!-- [fun_termometro_sht_down] -->
148void termometro_sht_down( uint8_t scheda_su_scheda_giu, uint8_t canale ){
149
150 //< registri termometro
151 #define reg_temperatura 0
152 #define reg_configuration 1
153 #define reg_control_status 4
154 //< Commands
155 #define Shut_down_and_one_shot_command_for_config_reg 0x84
156 #define Shut_down_config_reg 0x80
157 #define Max_accuracy_command_for_control_reg 0x60
158 #define maschera_DAV 1
159
160 uint8_t comando1[]={reg_control_status,Max_accuracy_command_for_control_reg};
161 uint8_t comando2[]={reg_configuration, Shut_down_config_reg};
162// uint8_t comando2[]={reg_configuration, 0};
163 uint8_t comando3[]={reg_temperatura};
164 uint8_t comando4[]={reg_control_status};
165 uint8_t lettura[2];
166
167
168//void I2C_mux_select_ch( uint8_t scheda_su_scheda_giu, I2C_mainboard,uint8_t canale_da_abilitare)
169 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, termometro_adrress[canale].quale_I2C);
170
171 I2C_mux -> MasterTransmit( termometro_adrress[canale].indirizzo_I2C, comando1, 2,false); //bestacuracy
172 while( I2C_mux -> GetStatus().busy); // White transmission complete
174 I2C_mux -> MasterTransmit( termometro_adrress[canale].indirizzo_I2C, comando2, 2,false); //onseshot meas
175 while( I2C_mux -> GetStatus().busy); // White transmission complete
176 Aspetta_tanti_ms(150);
178
179 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, I2C_mux_disabilita_tutto);
180
181}
182//! <!-- [fun_termometro_sht_down] -->
183
184//FINE CROSS
185
186extern ARM_DRIVER_I2C Driver_I2C2; // Viene inclusa la Periferica I2C2
187
188//ARM_DRIVER_I2C * I2C_termometro_drv = &Driver_I2C2; // Viene creato un puntatore a Driver_I2C2
189
190
191
192/*****************************************************************************
193 Interrupt della Periferica I2C_termometro
194 ******************************************************************************/
195void I2C_termometro_SignalEvent_t (uint32_t event)
196{
197 if(event==ARM_I2C_EVENT_TRANSFER_DONE) // Ricezione e trasmissione finita sia del master che dello slave
198 {
199 __NOP();
200 }
201 if(event==ARM_I2C_EVENT_SLAVE_TRANSMIT)
202 {
203 __NOP();
204 }
205 if(event==ARM_I2C_EVENT_SLAVE_RECEIVE)
206 {
207 __NOP();
208 }
209}
210
211
212
213
214/*****************************************************************************
215 I2C_termometro_Initialize
216 *****************************************************************************/
217void I2C_termometro_Initialize (void)
218{
219
220 I2C_termometro_drv->Initialize (I2C_termometro_SignalEvent_t); // Viene inizializzata la periferica I2C
221 I2C_termometro_drv->PowerControl (ARM_POWER_FULL); // Viene accesa la periferica
222 I2C_termometro_drv->Control (ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST); // Viene impostata la velocit\'a del Bus
223 I2C_termometro_drv->Control (ARM_I2C_BUS_CLEAR, 0);
224}
volatile uint32_t Error_bad_operation
exploited to mark the errors
void ERROR_codifica_errore(uint8_t scheda_su_scheda_giu, unsigned char error_addres, unsigned char code_to_shift, uint8_t reset_count_se_0)
If an error is found its flag is codified here.
@ I2C_error_termometro_0
termometro ch0
@ error_address_I2C0_B
Error register B for I2C0
void I2C_mux_select_ch(uint8_t scheda_su_scheda_giu, uint8_t mainboard_postmainboard, uint8_t canale_da_abilitare)
The I2C mux.
Definition: I2C_mux.c:100
#define I2C_mux_disabilita_tutto
i2C transmission/reception was bad
Definition: I2C_mux.h:24
#define I2C_mux_abilita_2
Enable channel 2.
Definition: I2C_mux.h:27
#define I2C_mux_abilita_1
Enable channel 1.
Definition: I2C_mux.h:26
#define I2C_mux_abilita_0
Enable channel 0.
Definition: I2C_mux.h:25
const struct address_detector_bias_trimmer_type termometro_adrress[6]
Thermometer selection structure.
void termometro_sht_down(uint8_t scheda_su_scheda_giu, uint8_t canale)
void termometro_lettura(uint8_t scheda_su_scheda_giu, uint8_t canale, uint32_t *temperatura_in_microK)
Read the termometer on preamplifier.
ARM_DRIVER_I2C Driver_I2C2
#define termometro_I2C_Address_dispari
I2C address of termometer in preamplifiers 1, 3 and 5.
#define termometro_I2C_Address_pari
I2C address of termometer in preamplifiers 0, 2 and 4.
static ARM_DRIVER_I2C * I2C_termometro_drv
Puntatore alla periferica I2C2.
void Aspetta_tanti_ms(int millisecondi)
The timing function.
Definition: Timer.c:52
Coordinates for the preamplifier and onboard EPROMs.
Definition: Trimmer.h:97