Firmware – Stefano Allegri https://www.allegristefano.eu la cooperazione è alla base di una buona progettazione Sun, 29 May 2022 07:48:19 +0000 it-IT hourly 1 https://wordpress.org/?v=5.3.15 MSP430 – Puntatori a struttura ANSI C https://www.allegristefano.eu/2022/05/29/msp430-puntatori-a-struttura-ansi-c/ https://www.allegristefano.eu/2022/05/29/msp430-puntatori-a-struttura-ansi-c/#respond Sun, 29 May 2022 07:48:16 +0000 https://www.allegristefano.eu/?p=219 Per poter accedere ai dati di una struttura un modo è quello di accedere ai singoli elementi della struttura, un’altro è quello di accedere all’area di memoria nella quale quell’elemento è memorizzato. pragma pack(push,1) // definisce l'allineamento della compressione per //i membri della struttura a 1Byte // l'effetto è che non ci sono byte non […]

L'articolo MSP430 – Puntatori a struttura ANSI C proviene da Stefano Allegri.

]]>
Per poter accedere ai dati di una struttura un modo è quello di accedere ai singoli elementi della struttura, un’altro è quello di accedere all’area di memoria nella quale quell’elemento è memorizzato.

 pragma pack(push,1)     // definisce l'allineamento della compressione per 
                         //i membri della struttura a 1Byte
                         // l'effetto è che non ci sono byte non 
                         //utilizzati tra i vari campi della struttura e 
                         // i dati salvaìti in memoria occupando la somma 
                         // delle grandezze dei cami dichiarati nella 
                         //struttura 
 typedef struct definizioneStruttura {
     float primo;      // 4 byte
     float secondo;    // 4byte
     int terzo;        // 2byte
 } definizioneStruttura;
 pragma pack(pop)
 definizioneStruttura Struttura;
 int main(void) {
 unsigned int *pStruttura=&Struttura;    // il puntatore è di tipo 
                                         // unsigned int = 2 Byte
   Struttura.primo = 1.1;
   Struttura.secondo = 2.2;
   Struttura.terzo = 3;                //inizializzazione valore ==> 3
   *(pStruttura+4) = 0x0400;           // per scorrere i campi della
                                       // struttura ci si sposta sommando 
                                       // 4 al puntatore alla struttura
                                       // per avanzare di 4 volte la 
                                       // dimensione del puntatore alla 
                                       // struttura, sommando 2 si 
                                       // punterebbe a "Struttura.secondo"  
   
   Printf("valore terzo %d", Struttura.terzo);
 }
 // stamperà il valore ==> 4

per MSP430 la memorie viene indirizzata con 2 byte è quindi possibile definire un puntatore di tipo unsigned int e assegnare a questo il valore di primo elemento di memoria della struttura

 unsigned int *pStruttura=&Struttura;    // il puntatore è di tipo 
                                         // unsigned int = 2 Byte 

&Struttura

il carattere speciale & consente di recuperare l’indirizzo di memoria della Struttura

per accedere al contenuto della struttura si fa avanzare il puntatore a step di 2 byte alla volta (questo perchè il puntatore è definito come unsigned int == 2byte)

    *(pStruttura+4) = 0x0400;           // per scorrere i campi della
                                       // struttura ci si sposta sommando 
                                       // 4 al puntatore alla struttura
                                       // per avanzare di 4 volte la 
                                       // dimensione del puntatore alla 
                                       // struttura 

per modificare il valore di Struttura.terzo è necessario tenere in considerazione l’ordine dei byte che nel caso dell’MSP430 è

little endian = indirizzo più piccolo contiene il byte meno significativo

Ordine dei byte (endianness)

L’ordine dei byte (conosciuto anche come big-endianlittle-endian o middle-endian a seconda dei metodi differenti), in informatica, indica modalità differenti usate dai calcolatori per immagazzinare in memoria dati di dimensione superiore al byte (es. worddwordqword).

L'articolo MSP430 – Puntatori a struttura ANSI C proviene da Stefano Allegri.

]]>
https://www.allegristefano.eu/2022/05/29/msp430-puntatori-a-struttura-ansi-c/feed/ 0
OpenLog – datalogger con codice sorgente ANSI C https://www.allegristefano.eu/2020/03/21/openlog-datalogger-con-codice-sorgente-ansi-c/ https://www.allegristefano.eu/2020/03/21/openlog-datalogger-con-codice-sorgente-ansi-c/#comments Sat, 21 Mar 2020 15:41:14 +0000 https://www.allegristefano.eu/?p=43 Open Source Datalogger, the new project developed in collaboration with the tested group of professionals of www.visualizza3d.com allows to acquire analogue inputs, PT100, PT1000, in thermocouple, digital inputs, data coming from peripherals connected via RS232 or RS485 with ModBus protocols or owners. It offers a high level of connectivity by integrating on board a Radio […]

L'articolo OpenLog – datalogger con codice sorgente ANSI C proviene da Stefano Allegri.

]]>

Open Source Datalogger, the new project developed in collaboration with the tested group of professionals of www.visualizza3d.com allows to acquire analogue inputs, PT100, PT1000, in thermocouple, digital inputs, data coming from peripherals connected via RS232 or RS485 with ModBus protocols or owners.

It offers a high level of connectivity by integrating on board a Radio transmitter on a free frequency of 868MHz that allows connections with remote units of the same type up to 3 km away.

Bluetooth interface, with which through the APP for Android it is possible to configure the parameters of the inputs and monitor the status of the input values ​​in real time. LoraWAN connectivity with integrated module on board the data logger.

GPRS connectivity for sending data to our Cloud.

Using the USB port, it is possible to configure a new sensor, monitor the status of the inputs, and download the data stored in the memory (128MByte) on the system.

Features:

• 6 analog inputs, configurable 0..1V or 0..10V or 0..20mA or 4..20mA

• 4 PT100 or PT1000 inputs or resistive measurement

• 4 inputs for thermocouple

• 2 digital inputs for pulse sampling or digital states

• 1 serial input RS232 or RS485 with ModBus protocol or owner

• 4 relay outputs

• BOX IP65 25x16x8 cm, 400gr

• power supply with 10 lithium batteries, connected in parallel, each 4V @ 3A / h for a total of 30A / h that guarantee a typical autonomy of 6 months of acquisitions

• integrated recharge from solar panel or external 12V power supply

• display for real time display of the data acquired by the sensors and the serial

• The system is supplied with compiled libraries that offer connectivity to the peripherals on the board, and is also supplied complete with wiring diagram. The development environment is Open Source: Texas Instruments Code Composer. In this way the end user can write his own application using the library developed by us to interface with the machine’s hardware.

L'articolo OpenLog – datalogger con codice sorgente ANSI C proviene da Stefano Allegri.

]]>
https://www.allegristefano.eu/2020/03/21/openlog-datalogger-con-codice-sorgente-ansi-c/feed/ 2