CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
I2C_to_parallel.c
Go to the documentation of this file.
1
2
3#include "tutti_gli_header.h"
4
5// DOCUMENTAZIONE DOXYGEN
6/// \file
7
8/*! \page I2C_to_parallel
9*\brief <span style="color:red;"> <b> This chip is exploited to set the chips select </b> </span>
10*\tableofcontents
11
12 \b SUMMARY:
13*\arg \ref managing_of_I2C_to_parallel
14
15
16*\section managing_of_I2C_to_parallel User use of I2C to Parallel
17<hr width="75%" size="10" align="left">
18
19\n This chip is the PCA9554 (<a href="./File_pdf/PCA9554_9554A.pdf" target=_blank><b>PCA9554A datasheet</b></a>).
20
21\n This chip is exploited to manage the chip select pins of the chips that work with SPI or with a parallel bus. They are 3 chips that are selected, by mean of the user functions by:
22 - #I2C_to_Parallel_name_1
23 - #I2C_to_Parallel_name_2
24 - #I2C_to_Parallel_name_3
25
26 \n The 3 chips are I2C and their addresses, trasparent to the user, are:
27 - #I2C_to_Parallel_address_1
28 - #I2C_to_Parallel_address_2
29 - #I2C_to_Parallel_address_3
30
31\n There are 2 functions to use. The first is the initialization function: I2C_to_Parallel_ini_PCA9554() with input parameters: <i>uint8_t scheda_su_scheda_giu, uint8_t select_PCA</i>.
32The second operational function, I2C_to_Parallel_set_PCA9554_outputs_values() with input parameters: <i>uint8_t scheda_su_scheda_giu, uint8_t select_PCA, uint8_t value</i>
33is the one that allows to set the port.
34
35\n The PCA9554 has 4 commands listed below. Only the fourth command, which allows to set the chip as an output port,
36is exploited for our purpose. For diagnostic purpose the first command, the reading command, is exploited.
37\n The 4 commands are implicitily used in the above functions:
38 -# #I2C_to_Parallel_Command_read_output, Read output pin, either if they are inputs or outpus
39 -# #I2C_to_Parallel_Command_data_to_write, Data are written in the bits set as output
40 -# #I2C_to_Parallel_Command_polarity_inversion, Polarity inversion of the read bit, set all 0 in our case
41 -# #I2C_to_Parallel_Command_configuration_register, Configuration register, set to 0 for ouput of the corresponding bit
42
43\n The scheme of the PCA9554 is in Figure \ref Figure_I2C_to_parallel.
44
45
46 \n The first action to do is to initialize all the 3 PCA9554s. Here the case for the first:
47
48<span style="color:orange;"> <I>
49\code {.c}
50I2C_to_Parallel_ini_PCA9554( scheda_su_scheda_giu, I2C_to_Parallel_name_1 );
51\endcode
52</I> </span>
53
54\n Every chip select is active low, but one, so the starting output values, all chps off, transparent to user,
55is not 0xFF for the 3 chpis, but:
56 - #I2C_to_Parallel_1_ini_set
57 - #I2C_to_Parallel_2_ini_set
58 - #I2C_to_Parallel_3_ini_set
59
60\n To easy the job there is the 4 taps vector #I2C_to_Parallel_ini_set that contains the 3 values above in the last 3 positions
61(the first poition is unusued).
62
63\n There are also structured vectors of constants that have set the parameters of interest regarding the PCA and its pin to select:
64 *\snippet I2C_to_parallel.h struct_chip_select_type
65
66\n The I2C_to_Parallel_set_PCA9554_outputs_values() allows to set any value at the output port and it is usefull for parallel bus driven chips,
67such as the analog mux \ref Multiplexer_strutture_funzioni_definizioni "ADG14082". For this latter refer to its
68\ref Multiplexer_strutture_funzioni_definizioni "specific page".
69\n Whenever we need to manage a SPI driven chip the first think to do is to anable it and the first function to use is the
70I2C_to_Parallel_set_PCA9554_outputs_values() to enable the chip; after the job is done, do not forget to disable the chip. Here
71is an example:
72
73<span style="color:orange;"> <I>
74\code {.c}
75speak_with_a_chipX( scheda_su_scheda_giu, #I2C_to_Parallel_name_1 ){
76I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_scheda_giu, select_PCA_of_chipX, select_PCA_of_chipX ) ;
77
78// Do the job
79
80I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_scheda_giu, select_PCA_of_chipX, I2C_to_Parallel_ini_set[ini_value_for_the_PCA_of_chipX]) ;
81}
82\endcode
83</I> </span>
84
85\sa A more specific use of the I2C_to_Parallel_set_PCA9554_outputs_values() function can be seen here Relays_driver_set_reset_channel().
86\n The function is used in: Analog_mux_line_to_select_deselect(), instr_inizializza_tutto_da_zero_function(), Relays_driver_set_reset_channel()
87and PGA_GAIN().
88
89\note A mnemonic way to refer to the output pins is to use the enum pin_x, x=1,..,8:
90\snippet I2C_to_parallel.c enum_I2C_to_Parallel_pin_type
91
92
93*\anchor Figure_I2C_to_parallel
94*\image html I2C_to_Parallel_PCA9554.png "Figure I2C_to_parallel 1: I2C to parallel PCA9554" width=60%
95*\image latex I2C_to_Parallel_PCA9554.png "Figure I2C_to_parallel 1: I2C to parallel PCA9554" width=60%
96
97
98 The codes for mamnaging the mux are:
99 - \ref I2C_to_parallel.h
100 - \ref I2C_to_parallel.c
101
102<!-- pappa -->
103*/
104
105//INIZIO CROSS
106
107/*! \brief These are the aliases for the I2C to parallel output
108 */
109 //! <!-- [enum_I2C_to_Parallel_pin_type] -->
111 pin_1, //!< This is the first pin of the output port
112 pin_2,
113 pin_3,
114 pin_4,
115 pin_5,
116 pin_6,
117 pin_7,
118 pin_8 //!< This is the last pin of the output port
119} ;
120 //! <!-- [enum_I2C_to_Parallel_pin_type] -->
121
122
123//struct chip_select_type{
124//uint8_t I2C_to_parallel_chip_num;
125//uint8_t I2C_to_parallel_chip__pin_num;
126//} ;
127
128/*! \brief This is the vector of constant values which allows to enable the relays drivers of each channels, one at a time.
129Every selecting pin to be enabled needs to select the chip, namely the port to which is connected, and the pin on the port.
130
131\note <b> ... & #I2C_to_Parallel_2_ini_set </b> The analog mux ADG1408 chip select is idle when 0 it equals 0x7F
132\n <b> ... & #I2C_to_Parallel_2_ini_set </b> is also set for the reson above.
133\n More about the ADG1408 can be found at \ref Multiplexer_strutture_funzioni_definizioni.
134\n \emoji :wink:
135
136*/
137 //! <!-- [vec_detector_chip_select_bias] -->
138const struct chip_select_type detector_chip_select_bias[channel_number]=
140 I2C_to_Parallel_name_1, ~(1<<pin_3 ),
141 I2C_to_Parallel_name_1, ~(1<<pin_5 ),
142 I2C_to_Parallel_name_1, ~(1<<pin_7 ),
145 //! <!-- [vec_detector_chip_select_bias] -->
146
147
148const struct chip_select_type detector_reset_all_relays_driver={I2C_to_Parallel_name_3, (~(1<<pin_1 ) & I2C_to_Parallel_3_ini_set)} ; //< reset signal to the reset pin of
149 //the 6 relays drivers.
150
151const struct chip_select_type PGA_DAC_chip_select[channel_number]={I2C_to_Parallel_name_1, ~(1<<pin_2 ),
152 I2C_to_Parallel_name_1, ~(1<<pin_4 ),
153 I2C_to_Parallel_name_1, ~(1<<pin_6 ),
154 I2C_to_Parallel_name_1, (uint8_t) ~(1<<pin_8 ),
157 //! ...
159
160 /*! \brief The I2C_to_Parallel_ini_PCA9554 inits the I2C_to_Parallel_ini_PCA9554 chips by setting all the outputs high,
161 but the 2 chip select analog muxes, to disable all the chips
162
163 *\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
164 *\param[in] select_PCA the channel in the mux to be enabled, 1, 2 or 3
165 *\return No Parameters
166
167 *\snippet{lineno} I2C_to_parallel.c fun_I2C_to_Parallel_ini_PCA9554
168 */
169 //! <!-- [fun_I2C_to_Parallel_ini_PCA9554] -->
170void I2C_to_Parallel_ini_PCA9554( uint8_t scheda_su_scheda_giu, uint8_t select_PCA ){
171 uint8_t indirizzo= I2C_to_Parallel_address_1; //We set the first chip; below we will see if this is true
172 uint8_t impostazione_iniziale_della_porta= I2C_to_Parallel_1_ini_set; //Default setting for first chip is this.
173 uint8_t comando[]={I2C_to_Parallel_Command_configuration_register,0}; //the value of 0 set all bits as ouput and default to 1
174
175 if ( select_PCA == I2C_to_Parallel_name_2){
176 indirizzo= I2C_to_Parallel_address_2;
177 impostazione_iniziale_della_porta=I2C_to_Parallel_2_ini_set;
178 }else if (select_PCA == I2C_to_Parallel_name_3){
179 indirizzo= I2C_to_Parallel_address_3;
180 impostazione_iniziale_della_porta=I2C_to_Parallel_3_ini_set;
181 }
182//void I2C_mux_select_ch( uint8_t scheda_su_scheda_giu, I2C_mainboard,uint8_t canale_da_abilitare)
183 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, I2C_mux_abilita_3); //I2C_mux_abilita_3= the i2C connected to the PCA's
184
185 I2C_mux -> MasterTransmit( indirizzo, comando, 2,false); //Set all bits as outputs
186 while( I2C_mux -> GetStatus().busy); // White transmission complete
187
189 comando[1]= impostazione_iniziale_della_porta; //Ouputs all high
190 I2C_mux -> MasterTransmit( indirizzo, comando, 2,false); //setbuf all bits to high
191 while( I2C_mux -> GetStatus().busy); // White transmission complete
192
194 I2C_mux -> MasterTransmit( indirizzo, comando, 1,true); //Set input register to read
195 while( I2C_mux -> GetStatus().busy); // White transmission complete
196 comando[0]=0;
197 comando[1]=0;
198 I2C_mux -> MasterReceive( indirizzo, comando, 1,false); //Read back, not needed
199 while( I2C_mux -> GetStatus().busy);
200 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, I2C_mux_disabilita_tutto); //Idle
201}
202 //! <!-- [fun_I2C_to_Parallel_ini_PCA9554] -->
203
204
205 /*! \brief The function I2C_to_Parallel_set_PCA9554_outputs_values allow to set the output pin of the I2C to parallel, there are
206structures for this. The detector: detector_chip_select_bias, the PGA_DAC
207
208 *\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
209 *\param[in] select_PCA the mux to be enabled, 1, 2 or 3
210 *\param[in] value the vlue to be set
211 *\return No Parameters
212
213
214 *\snippetlineno I2C_to_parallel.c fun_I2C_to_Parallel_set_PCA9554_outputs_values
215 */
216 //! <!-- [fun_I2C_to_Parallel_set_PCA9554_outputs_values] -->
217void I2C_to_Parallel_set_PCA9554_outputs_values( uint8_t scheda_su_scheda_giu, uint8_t select_PCA, uint8_t value ){
218 uint8_t indirizzo= I2C_to_Parallel_address_1; //Indirizzo di default
219 uint8_t comando[]={I2C_to_Parallel_Command_data_to_write, value }, scheda_su_scheda_giu_qui; //All bits set to ouput and to 1
220
221 if ( select_PCA == I2C_to_Parallel_name_2){
222 indirizzo= I2C_to_Parallel_address_2;
223 }else if (select_PCA == I2C_to_Parallel_name_3){
224 indirizzo= I2C_to_Parallel_address_3;
225 }
226
227
228//void I2C_mux_select_ch( uint8_t scheda_su_scheda_giu, uint8_t canale_da_abilitare)
229 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, I2C_mux_abilita_3);
230
231 I2C_mux -> MasterTransmit( indirizzo, comando, 2,false); //Set all bits as outputs
232 while( I2C_mux -> GetStatus().busy); // White transmission complete
233
234
236 I2C_mux -> MasterTransmit( indirizzo, comando, 1,true); //Set input register to read
237 while( I2C_mux -> GetStatus().busy); // White transmission complete
239 comando[0]=0;
240 comando[1]=0;
241 I2C_mux -> MasterReceive( indirizzo, comando, 1,false); //Read back, not needed
242 while( I2C_mux -> GetStatus().busy);
244}
245//! <!-- [fun_I2C_to_Parallel_set_PCA9554_outputs_values] -->
246
247//Fine cross
248
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_I2C_to_parallel_PCA9554_0
I2C to parallel conversion ch0.
@ error_address_I2C0
Error register A 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_3
Enable channel 3.
Definition: I2C_mux.h:28
void I2C_to_Parallel_set_PCA9554_outputs_values(uint8_t scheda_su_scheda_giu, uint8_t select_PCA, uint8_t value)
The function I2C_to_Parallel_set_PCA9554_outputs_values allow to set the output pin of the I2C to par...
const struct chip_select_type detector_chip_select_bias[6]
This is the vector of constant values which allows to enable the relays drivers of each channels,...
const uint8_t I2C_to_Parallel_ini_set[4]
...
void I2C_to_Parallel_ini_PCA9554(uint8_t scheda_su_scheda_giu, uint8_t select_PCA)
The I2C_to_Parallel_ini_PCA9554 inits the I2C_to_Parallel_ini_PCA9554 chips by setting all the output...
I2C_to_Parallel_pin_type
These are the aliases for the I2C to parallel output.
@ pin_1
This is the first pin of the output port.
@ pin_8
This is the last pin of the output port.
#define I2C_to_Parallel_name_3
the third PCA
#define I2C_to_Parallel_Command_configuration_register
Configuration register, set to 0 for ouput of the corresponding bit.
#define I2C_to_Parallel_Command_read_output
Read output pin, either if they are inputs or outpus.
#define I2C_to_Parallel_address_2
address of the second I2C to parallel
#define I2C_to_Parallel_address_3
address of the third I2C to parallel
#define I2C_to_Parallel_2_ini_set
#define I2C_to_Parallel_name_1
the first PCA
#define I2C_to_Parallel_1_ini_set
#define I2C_to_Parallel_address_1
address of the first I2C to parallel
#define I2C_to_Parallel_name_2
the second PCA
#define I2C_to_Parallel_3_ini_set
#define I2C_to_Parallel_Command_data_to_write
Data are written in the bits set as output.
This is the struct definition for the selection of the chip select of the relays drivers.