Combinación de los datos de CÓDIGO recibidos del LTC2498 a través de SPI con el enlace de radio entre dos ATmega128RFA1

1

Le agradecería mucho sus sugerencias para la definición de mi problema actual:

Tengo un microcontrolador ATmega128RFA1 con Zigbee integrado con UART-USB (Convertidor TTL) conectado a la PC.

Tengo un segundo idénticamente con el primer Microcontrolador (ATmega128RFA1) conectado por SPI a un Termochip LTC2498 analógico-digital.

1.-TengoelcódigoCparalosdosmicrocontroladores,enviandoyrecibiendodatosporcomunicaciónderadio(BibliotecadeUracoli).

Código1=( enlace )

Código 2 = ( enlace )

2.-Por otra parte, tengo el código C para recibir datos de LTC2498 a través de SPI (Plan actual con solo un ATmega128RFA1):

LTC2498 - SPI - uC (programado con el código 3) - UART_USB - PC.

Código 3 = lectura de datos de LTC2498:

#include <avr/io.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <util/delay.h>

#define DD_MISO 3
#define DD_MOSI 2
#define DD_SCK 1
#define DD_SS 0

void uart_init()
{
    uint16_t temp = ((8000000)/(9600.0*16)-1); //Berechnung Übertragungsgeschwindigkeit

    UBRR0L = temp; //Übertragungsgeschwindigkeit übermitteln
    UBRR0H = temp>>8; 
    UCSR0B |= (1<<TXEN0)|(1<<RXEN0)|(1<<RXCIE0); //Senden und Empfangen freischalten   
    UCSR0C |= (1<<UCSZ00)|(1<<UCSZ01);  //Übertragungsformat: 8-Bit
}

int sendestring(char *s)
{
    int i=0; 
    for(i=0; s[i] != '
while(1)
{
    WAIT500MS();
    if (tx_in_progress == false)
    {
        temp = read_ltc2498();
        len = snprintf(&txfrm[3], 122, "temp = %d\n", temp);
        txfrm[0] = len + 3 + 2;
        txfrm[2] = tx_cnt;
        trx_frame_write (sizeof(txfrm), txfrm);
        tx_in_progress = true;
        TRX_SLPTR_HIGH();
        TRX_SLPTR_LOW();
        LED_SET(1);
        LED_TOGGLE(0);
    }
}
'; i++) { while bit_is_clear(UCSR0A, UDRE0); //warten, bis UDRE0 = 1 (Senderegister frei) UDR0 = s[i]; //ein Zeichen senden } return 0; } void SPI_MasterInit(void) { //Outputs: MOSI, SCK, SS DDRB = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS); //Enable SPI, Master-Mode, set clock rate fck/16 SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); } int SPI_MasterTransmit(char MOSI) { //start Transmission SPDR = MOSI; //white for transmission complete while(!(SPSR & (1<<SPIF))); //returned data from slave to master return SPDR; } int main() { char str[20]; // Thermoelement an CH0 und CH1 char masterOut1 = 0b10100000; //char masterOut2 = 0b10000000; // interne Temperaturmessung: char masterOut2 = 0b11000000; char result; uint32_t masterIn = 0; uint32_t Temp = 0; uart_init(); SPI_MasterInit(); for(;;) { _delay_ms(500); //CS des Thermochips auf low PORTB &= !(1<<DD_SS); //Byte1 result = SPI_MasterTransmit(masterOut1); masterIn = (result & 0b00011111); //die ersten drei Bit löschen //für Debugging sendestring(" result1: "); itoa(result, str, 2); //binär darstellen sendestring(str); //Byte2 result = SPI_MasterTransmit(masterOut2); masterIn = (masterIn<<8) + result; //Byte3 result = SPI_MasterTransmit(0); masterIn = (masterIn<<8) + result; //Byte4 result = SPI_MasterTransmit(0); masterIn = (masterIn<<8) + result; //CS des Thermochips auf high PORTB |= (1<<DD_SS); masterIn = (masterIn>>5) & 0b00000000111111111111111111111111; //die letzten 5 Bit löschen sendestring(" masterIn: "); sprintf(str, "%ld", masterIn); sendestring(str); Temp = (masterIn*4/1570)-273; sendestring(" Temp: "); sprintf(str, "%ld", Temp); sendestring(str); _delay_ms(2000); } return 0; }

Necesito implementar datos de lectura de LTC2498 (Código 3) con la Radio Comunicación. Plan deseado:

---- LTC2498 - SPI - uC - (Enlace de radio) - uC - UART_USB - PC

Por ejemplo, solo tengo un ejemplo para recibir un mensaje de "Hola mundo" con el Plan de deseos funcionando perfectamente:                                                                                                  uC (programado con el código 4) - (Enlace de radio) - uC (programado con el código 5) - UART_USB - PC

Le muestro los cambios: Código 4 = Código 1 y Código 5 = Código 2 pero modificado.

NecesitoimplementarSPIcomounafunción,yporejemplo,algoasíenelcódigoenviado:

#include"board.h"
#include "transceiver.h"
#include "ioutil.h"
#include "xmpl.h"


static volatile bool tx_in_progress;
static volatile uint8_t tx_cnt;
static volatile uint32_t temp;
static volatile uint32_t len;



int main(void)
{
trx_regval_t rval;


uint8_t txfrm[] = {1,0, /* faked ieee 802.15.4 data frame control field
                     * this is just needed, that a sniffer has to display something.*/
               42,  /* sequence counter, updated by software */
              'h','e','l','l','o',' ','µ','r','a','c','o','l','i','!', /* data */
              'X','X' /* these bytes are overwritten from transceivers CRC generator just before sent. */
              };
/* This will stop the application before initializing the radio transceiver
 * (ISP issue with MISO pin, see FAQ)
 */
trap_if_key_pressed();

/* Step 0: init MCU peripherals */
LED_INIT();
trx_io_init(SPI_RATE_1_2);
LED_SET_VALUE(LED_MAX_VALUE);
LED_SET_VALUE(0);

/* Step 1: initialize the transceiver */
DELAY_US(TRX_INIT_TIME_US);
TRX_RESET_LOW();
TRX_SLPTR_LOW();
DELAY_US(TRX_RESET_TIME_US);
TRX_RESET_HIGH();
trx_reg_write(RG_TRX_STATE,CMD_TRX_OFF);
DELAY_US(TRX_INIT_TIME_US);
rval = trx_bit_read(SR_TRX_STATUS);
ERR_CHECK_DIAG(TRX_OFF!=rval,1);
LED_SET_VALUE(1);

/* Step 2: setup transmitter
 * - configure radio channel
 * - enable transmitters automatic crc16 generation
 * - go into TX state,
 * - enable "transmit end" IRQ
 */
trx_bit_write(SR_CHANNEL,CHANNEL);
trx_bit_write(SR_TX_AUTO_CRC_ON,1);
trx_reg_write(RG_TRX_STATE,CMD_PLL_ON);
#if defined(TRX_IRQ_TRX_END)
trx_reg_write(RG_IRQ_MASK,TRX_IRQ_TRX_END);
#elif defined(TRX_IRQ_TX_END)
trx_reg_write(RG_IRQ_MASK,TRX_IRQ_TX_END);
#else
#  error "Unknown IRQ bits"
#endif
sei();
LED_SET_VALUE(2);

/* Step 3: send a frame each 500ms */
tx_cnt = 0;
tx_in_progress = false;
LED_SET_VALUE(0);

while(1)
{
    WAIT500MS();
    if (tx_in_progress == false)
    {
//------------------------------------------------------------------------------
//------------PART TO MODIFY------------------------


        temp = read_ltc2498();


        len = snprintf(&txfrm[3], 122, "temp = %d\n", temp);
//The transmission is from 122 to 127 (last), 3 byte block home and State 2.
        txfrm[0] = len + 3 + 2;


//------------------------------------------------------------------------------
//-----------------------------------------------------------------------------
        txfrm[2] = tx_cnt;
        trx_frame_write (sizeof(txfrm), txfrm);
        tx_in_progress = true;
        TRX_SLPTR_HIGH();
        TRX_SLPTR_LOW();
        LED_SET(1);
        LED_TOGGLE(0);
        }
    }
}

#if defined(TRX_IF_RFA1)
ISR(TRX24_TX_END_vect)
{
/* transmission completed */
tx_in_progress = false;
tx_cnt ++;
LED_CLR(1);
}
#else  /* !RFA1 */
ISR(TRX_IRQ_vect)
{
static volatile trx_regval_t irq_cause;
irq_cause = trx_reg_read(RG_IRQ_STATUS);
if (irq_cause & TRX_IRQ_TRX_END)
{
    /* transmission completed */
    tx_in_progress = false;
    tx_cnt ++;
    LED_CLR(1);
    }
}
#endif

/* EOF */

¿Cómo puedo hacerlo? Todos mis intentos de compilación están mal. ¿Podrías ayudarme?

Muchas gracias

Todavía tengo problemas de compilación. He usado parte de tu código, pero no estoy seguro de haberlo hecho correctamente. ¿Podría decirme qué debo corregir? Le muestro ambos códigos.

--- LTC2498 - SPI - uC (programado con código de envío) - (Enlace de radio) - uC (programado con código de recepción) - UART_USB - PC

Código de envío:

Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT xmpl_trx_tx.o -MF dep/xmpl_trx_tx.o.d  -c  ../xmpl_trx_tx.c

../xmpl_trx_tx.c: In function 'main':
../xmpl_trx_tx.c:80:13: warning: implicit declaration of function 'read_ltc2498' [-Wimplicit-function-declaration]
../xmpl_trx_tx.c:83:13: warning: pointer targets in passing argument 1 of 'snprintf' differ in signedness [-Wpointer-sign]
In file included from C:\Users\EKTOR\Desktop\Proyecto111\Progs\uracoli-src-0.4.0\xmpl\..\inc/ioutil.h:53:0,
                 from ../xmpl_trx_tx.c:3:
../xmpl_trx_tx.c:83:13: warning: format '%d' expects argument of type 'int', but argument 4 has type 'uint32_t' [-Wformat]
Build succeeded with 3 Warnings...

ERRORES DE COMPILACIÓN ENVIAR CÓDIGO :

#include "board.h"
#include "transceiver.h"
#include "ioutil.h"
#include  <util/crc16.h>
#include "xmpl.h"

#include <avr/io.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <util/delay.h>


#define DD_MISO 3
#define DD_MOSI 2
#define DD_SCK 1
#define DD_SS 0


static uint8_t rxfrm[MAX_FRAME_SIZE];
static volatile uint8_t rxcnt;


//----------------------UART-------------------------------

void uart_init()
{
uint16_t temp = ((8000000)/(9600.0*16)-1); //Berechnung Übertragungsgeschwindigkeit

UBRR0L = temp; //Übertragungsgeschwindigkeit übermitteln
UBRR0H = temp>>8;

UCSR0B |= (1<<TXEN0)|(1<<RXEN0)|(1<<RXCIE0); //Senden und Empfangen freischalten


UCSR0C |= (1<<UCSZ00)|(1<<UCSZ01);  //Übertragungsformat: 8-Bit

}


int sendestring(char *s)
{
int i=0;

for(i=0; s[i] != '
Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT xmpl_trx_tx.o -MF dep/xmpl_trx_tx.o.d  -c  ../xmpl_trx_tx.c

../xmpl_trx_tx.c: In function '__vector_60':
../xmpl_trx_tx.c:197:9: error: conflicting types for 'str'

../xmpl_trx_tx.c:158:6: note: previous declaration of 'str' was here
../xmpl_trx_tx.c: In function 'sendToPC':
../xmpl_trx_tx.c:200:5: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness [-Wpointer-sign]
In file included from C:\Users\EKTOR\Desktop\Proyecto111\Progs\uracoli-src-0.4.0\xmpl\..\inc/ioutil.h:53:0,
                 from ../xmpl_trx_tx.c:3:
c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/stdio.h:669:12: note: expected 'char *' but argument is of type 'uint8_t *'
../xmpl_trx_tx.c:201:5: warning: pointer targets in passing argument 1 of 'sendestring' differ in signedness [-Wpointer-sign]
../xmpl_trx_tx.c:41:5: note: expected 'char *' but argument is of type 'uint8_t *'
../xmpl_trx_tx.c:203:5: error: 'Temp' undeclared (first use in this function)
../xmpl_trx_tx.c:203:5: note: each undeclared identifier is reported only once for each function it appears in
../xmpl_trx_tx.c:205:5: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness [-Wpointer-sign]
In file included from C:\Users\EKTOR\Desktop\Proyecto111\Progs\uracoli-src-0.4.0\xmpl\..\inc/ioutil.h:53:0,
                 from ../xmpl_trx_tx.c:3:
c:\program files\atmel\avr tools\avr toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/stdio.h:669:12: note: expected 'char *' but argument is of type 'uint8_t *'
../xmpl_trx_tx.c:206:5: warning: pointer targets in passing argument 1 of 'sendestring' differ in signedness [-Wpointer-sign]
../xmpl_trx_tx.c:41:5: note: expected 'char *' but argument is of type 'uint8_t *'
make: *** [xmpl_trx_tx.o] Error 1
Build failed with 2 errors and 4 warnings...
'; i++) { while bit_is_clear(UCSR0A, UDRE0); //warten, bis UDRE0 = 1 (Senderegister frei) UDR0 = s[i]; //ein Zeichen senden } return 0; } //--------------SPI----------------------- void SPI_MasterInit(void) { //Outputs: MOSI, SCK, SS DDRB = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS); //Enable SPI, Master-Mode, set clock rate fck/16 SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); } int SPI_MasterTransmit(char MOSI) { //start Transmission SPDR = MOSI; //wait for transmission complete while(!(SPSR & (1<<SPIF))); //returned data from slave to master return SPDR; } //----------------MAIN----------------- int main(void) { uart_init(); SPI_MasterInit(); trx_regval_t rval; /* This will stop the application before initializing the radio transceiver * (ISP issue with MISO pin, see FAQ) */ trap_if_key_pressed(); /* Step 0: init MCU peripherals */ LED_INIT(); trx_io_init(SPI_RATE_1_2); LED_SET_VALUE(LED_MAX_VALUE); LED_SET_VALUE(0); /* Step 1: initialize the transceiver */ TRX_RESET_LOW(); TRX_SLPTR_LOW(); DELAY_US(TRX_RESET_TIME_US); TRX_RESET_HIGH(); trx_reg_write(RG_TRX_STATE,CMD_TRX_OFF); DELAY_US(TRX_INIT_TIME_US); rval = trx_bit_read(SR_TRX_STATUS); ERR_CHECK(TRX_OFF!=rval); LED_SET_VALUE(1); /* Step 2: setup transmitter * - configure radio channel * - go into RX state, * - enable "receive end" IRQ */ trx_bit_write(SR_CHANNEL,CHANNEL); trx_reg_write(RG_TRX_STATE,CMD_RX_ON); #if defined(TRX_IRQ_TRX_END) trx_reg_write(RG_IRQ_MASK,TRX_IRQ_TRX_END); #elif defined(TRX_IRQ_RX_END) trx_reg_write(RG_IRQ_MASK,TRX_IRQ_RX_END); #else # error "Unknown IRQ bits" #endif sei(); LED_SET_VALUE(2); /* Step 3: Going to receive frames */ rxcnt = 0; LED_SET_VALUE(0); while(1); } #if defined(TRX_IF_RFA1) ISR(TRX24_RX_END_vect) { uint8_t flen, *pfrm, tmp; uint16_t crc; /* upload frame and check for CRC16 validity */ pfrm = rxfrm; flen = trx_frame_read(pfrm, sizeof(rxfrm), NULL); crc = 0; //--------ADD MESSEGE (data from LTC2498)-----//------- char str[20]; // Thermoelement an CH0 und CH1 char masterOut1 = 0b10100000; //char masterOut2 = 0b10000000; // interne Temperaturmessung: char masterOut2 = 0b11000000; char result; uint32_t readLTC2498 () { uint32_t masterIn = 0; //CS des Thermochips auf low PORTB &= !(1<<DD_SS); //Byte1 result = SPI_MasterTransmit(masterOut1); masterIn = (result & 0b00011111); //die ersten drei Bit löschen //Byte2 result = SPI_MasterTransmit(masterOut2); masterIn = (masterIn<<8) + result; //Byte3 result = SPI_MasterTransmit(0); masterIn = (masterIn<<8) + result; //Byte4 result = SPI_MasterTransmit(0); masterIn = (masterIn<<8) + result; //CS des Thermochips auf high PORTB |= (1<<DD_SS); masterIn = (masterIn>>5) & 0b00000000111111111111111111111111; //die letzten 5 Bit löschen return masterIn; } uint8_t str[127]; void sendToPC (uint32_t value) { sprintf(str,"masterIn: %ld",value); sendestring(str); Temp = (value*4/1570)-273; sprintf(str,"Temp:%ld",Temp); sendestring(str); } //--------------//-------------//--------------------//------------ do { crc = _crc_ccitt_update(crc, *pfrm++); } while(flen--); /* if crc is correct, update RX frame counter */ if (crc == 0) { rxcnt ++; } /* display current rx statistics * LED[0] toggles with every received frame * LED[1:n] display the count of frames received with valid CRC */ tmp = (rxcnt<<1) | ((LED_GET_VALUE()&1)^1); LED_SET_VALUE(tmp); } #else /* !RFA1 */ ISR(TRX_IRQ_vect) { static volatile trx_regval_t irq_cause; uint8_t flen, *pfrm, tmp; uint16_t crc; irq_cause = trx_reg_read(RG_IRQ_STATUS); if (irq_cause & TRX_IRQ_TRX_END) { /* upload frame and check for CRC16 validity */ pfrm = rxfrm; flen = trx_frame_read(pfrm, sizeof(rxfrm), NULL); crc = 0; do { crc = _crc_ccitt_update(crc, *pfrm++); } while(flen--); /* if crc is correct, update RX frame counter */ if (crc == 0) { rxcnt ++; } /* display current rx statistics * LED[0] toggles with every received frame * LED[1:n] display the count of frames received with valid CRC */ tmp = (rxcnt<<1) | ((LED_GET_VALUE()&1)^1); LED_SET_VALUE(tmp); } } #endif /* RFA1 */ /* EOF */

Código de recepción:

#include <avr/io.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <util/delay.h>

#define DD_MISO 3
#define DD_MOSI 2
#define DD_SCK 1
#define DD_SS 0

void uart_init()
{
    uint16_t temp = ((8000000)/(9600.0*16)-1); //Berechnung Übertragungsgeschwindigkeit

    UBRR0L = temp; //Übertragungsgeschwindigkeit übermitteln
    UBRR0H = temp>>8; 
    UCSR0B |= (1<<TXEN0)|(1<<RXEN0)|(1<<RXCIE0); //Senden und Empfangen freischalten   
    UCSR0C |= (1<<UCSZ00)|(1<<UCSZ01);  //Übertragungsformat: 8-Bit
}

int sendestring(char *s)
{
    int i=0; 
    for(i=0; s[i] != '
while(1)
{
    WAIT500MS();
    if (tx_in_progress == false)
    {
        temp = read_ltc2498();
        len = snprintf(&txfrm[3], 122, "temp = %d\n", temp);
        txfrm[0] = len + 3 + 2;
        txfrm[2] = tx_cnt;
        trx_frame_write (sizeof(txfrm), txfrm);
        tx_in_progress = true;
        TRX_SLPTR_HIGH();
        TRX_SLPTR_LOW();
        LED_SET(1);
        LED_TOGGLE(0);
    }
}
'; i++) { while bit_is_clear(UCSR0A, UDRE0); //warten, bis UDRE0 = 1 (Senderegister frei) UDR0 = s[i]; //ein Zeichen senden } return 0; } void SPI_MasterInit(void) { //Outputs: MOSI, SCK, SS DDRB = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS); //Enable SPI, Master-Mode, set clock rate fck/16 SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); } int SPI_MasterTransmit(char MOSI) { //start Transmission SPDR = MOSI; //white for transmission complete while(!(SPSR & (1<<SPIF))); //returned data from slave to master return SPDR; } int main() { char str[20]; // Thermoelement an CH0 und CH1 char masterOut1 = 0b10100000; //char masterOut2 = 0b10000000; // interne Temperaturmessung: char masterOut2 = 0b11000000; char result; uint32_t masterIn = 0; uint32_t Temp = 0; uart_init(); SPI_MasterInit(); for(;;) { _delay_ms(500); //CS des Thermochips auf low PORTB &= !(1<<DD_SS); //Byte1 result = SPI_MasterTransmit(masterOut1); masterIn = (result & 0b00011111); //die ersten drei Bit löschen //für Debugging sendestring(" result1: "); itoa(result, str, 2); //binär darstellen sendestring(str); //Byte2 result = SPI_MasterTransmit(masterOut2); masterIn = (masterIn<<8) + result; //Byte3 result = SPI_MasterTransmit(0); masterIn = (masterIn<<8) + result; //Byte4 result = SPI_MasterTransmit(0); masterIn = (masterIn<<8) + result; //CS des Thermochips auf high PORTB |= (1<<DD_SS); masterIn = (masterIn>>5) & 0b00000000111111111111111111111111; //die letzten 5 Bit löschen sendestring(" masterIn: "); sprintf(str, "%ld", masterIn); sendestring(str); Temp = (masterIn*4/1570)-273; sendestring(" Temp: "); sprintf(str, "%ld", Temp); sendestring(str); _delay_ms(2000); } return 0; }

CÓDIGO DE RECEPCIÓN DE ERRORES DE LA COMPILACIÓN :

#include "board.h"
#include "transceiver.h"
#include "ioutil.h"
#include "xmpl.h"


static volatile bool tx_in_progress;
static volatile uint8_t tx_cnt;
static volatile uint32_t temp;
static volatile uint32_t len;



int main(void)
{
trx_regval_t rval;


uint8_t txfrm[] = {1,0, /* faked ieee 802.15.4 data frame control field
                     * this is just needed, that a sniffer has to display something.*/
               42,  /* sequence counter, updated by software */
              'h','e','l','l','o',' ','µ','r','a','c','o','l','i','!', /* data */
              'X','X' /* these bytes are overwritten from transceivers CRC generator just before sent. */
              };
/* This will stop the application before initializing the radio transceiver
 * (ISP issue with MISO pin, see FAQ)
 */
trap_if_key_pressed();

/* Step 0: init MCU peripherals */
LED_INIT();
trx_io_init(SPI_RATE_1_2);
LED_SET_VALUE(LED_MAX_VALUE);
LED_SET_VALUE(0);

/* Step 1: initialize the transceiver */
DELAY_US(TRX_INIT_TIME_US);
TRX_RESET_LOW();
TRX_SLPTR_LOW();
DELAY_US(TRX_RESET_TIME_US);
TRX_RESET_HIGH();
trx_reg_write(RG_TRX_STATE,CMD_TRX_OFF);
DELAY_US(TRX_INIT_TIME_US);
rval = trx_bit_read(SR_TRX_STATUS);
ERR_CHECK_DIAG(TRX_OFF!=rval,1);
LED_SET_VALUE(1);

/* Step 2: setup transmitter
 * - configure radio channel
 * - enable transmitters automatic crc16 generation
 * - go into TX state,
 * - enable "transmit end" IRQ
 */
trx_bit_write(SR_CHANNEL,CHANNEL);
trx_bit_write(SR_TX_AUTO_CRC_ON,1);
trx_reg_write(RG_TRX_STATE,CMD_PLL_ON);
#if defined(TRX_IRQ_TRX_END)
trx_reg_write(RG_IRQ_MASK,TRX_IRQ_TRX_END);
#elif defined(TRX_IRQ_TX_END)
trx_reg_write(RG_IRQ_MASK,TRX_IRQ_TX_END);
#else
#  error "Unknown IRQ bits"
#endif
sei();
LED_SET_VALUE(2);

/* Step 3: send a frame each 500ms */
tx_cnt = 0;
tx_in_progress = false;
LED_SET_VALUE(0);

while(1)
{
    WAIT500MS();
    if (tx_in_progress == false)
    {
//------------------------------------------------------------------------------
//------------PART TO MODIFY------------------------


        temp = read_ltc2498();


        len = snprintf(&txfrm[3], 122, "temp = %d\n", temp);
//The transmission is from 122 to 127 (last), 3 byte block home and State 2.
        txfrm[0] = len + 3 + 2;


//------------------------------------------------------------------------------
//-----------------------------------------------------------------------------
        txfrm[2] = tx_cnt;
        trx_frame_write (sizeof(txfrm), txfrm);
        tx_in_progress = true;
        TRX_SLPTR_HIGH();
        TRX_SLPTR_LOW();
        LED_SET(1);
        LED_TOGGLE(0);
        }
    }
}

#if defined(TRX_IF_RFA1)
ISR(TRX24_TX_END_vect)
{
/* transmission completed */
tx_in_progress = false;
tx_cnt ++;
LED_CLR(1);
}
#else  /* !RFA1 */
ISR(TRX_IRQ_vect)
{
static volatile trx_regval_t irq_cause;
irq_cause = trx_reg_read(RG_IRQ_STATUS);
if (irq_cause & TRX_IRQ_TRX_END)
{
    /* transmission completed */
    tx_in_progress = false;
    tx_cnt ++;
    LED_CLR(1);
    }
}
#endif

/* EOF */
    
pregunta Ektor

1 respuesta

1

En el lado maestro, tendrás algo como:

while (1) {
    if(shouldreadLTC) {
        value = readLTC2498 ();
        sendToSlave (value);
        }
    }
//some timer routine to enable shouldreadLTC

Y en el lado esclavo:

while (1) {
    if (dataInBuffer()) {
        value = readBuffer();
        sendToPC (value);
        }
     }
//uart ringbuffer handling, interrupt enabled

Básicamente esto es lo que te gustaría lograr? Si entendí correctamente el código anterior, las siguientes funciones se conocen y funcionan:

uint32_t readLTC2498 () 
{
    uint32_t masterIn = 0;
   //CS des Thermochips auf low
    PORTB &= !(1<<DD_SS);


    //Byte1
    result = SPI_MasterTransmit(masterOut1);        
    masterIn = (result & 0b00011111);  //die ersten drei Bit löschen

    //Byte2
    result = SPI_MasterTransmit(masterOut2);
    masterIn = (masterIn<<8) + result;

    //Byte3
    result = SPI_MasterTransmit(0);
    masterIn = (masterIn<<8) + result;

    //Byte4
    result = SPI_MasterTransmit(0);
    masterIn = (masterIn<<8) + result;

    //CS des Thermochips auf high
    PORTB |= (1<<DD_SS);

    masterIn = (masterIn>>5) & 0b00000000111111111111111111111111; //die letzten 5 Bit löschen
return masterIn;
}
uint8_t g_str[128];
void sendToPC (uint32_t value)
{
    uint32_t Temp;
    sprintf(g_str, "masterIn: %ld", value);
    sendestring(g_str);

    Temp = (value*4/1570)-273;

    sprintf(g_str, " Temp: %ld", Temp);
    sendestring(g_str);
}

¿Lo que te falta es sendToSlave? más estos temporizador y uart interrupción de manejo?

    
respondido por el Gossamer

Lea otras preguntas en las etiquetas