This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430FR6047:MSP430 FR 6047 -通过 I2C 使用 EEPROM 进行写入和读取-浮动至十六进制转换并在逻辑分析仪中捕获十六进制值

Guru**** 1549780 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1344066/msp430fr6047-msp430-fr-6047--write-and-read-using-eeprom-via-i2c---float-to-hex-conversion-and-capturing-the-hex-value-in-logic-analyzer

器件型号:MSP430FR6047

MSP430-FR 6047模块在 I2C 协议中,我已经为写和读设置了一个特定的值。
 写我已经设置22.555656在一个数组,它只需要22个我需要写和捕获的值后的小数点。  
我需要执行任何转换过程吗?  
如果是、建议我执行一些步骤和逻辑

#include <msp430.h>
#include <stdint.h>

#define ENABLE_PINS 0xFFFE
#define DATA_SIZE 50 // Number of bytes to read
//unsigned int addr = 0;
unsigned int tx_byte_cnt = 0;
unsigned int rx_byte_cnt = 0;
float *g_buf = 0;
char data_in[DATA_SIZE] = {0};
volatile uint8_t bytes_received = 0;
volatile uint8_t eeprom_address = 0; // Starting EEPROM address

void mem_write(unsigned int eeprom_addr, float *buf, int len)
{
    //bytes_transmitted = 0;
   // addr = eeprom_addr;
    g_buf = buf;
    rx_byte_cnt = 0;
    tx_byte_cnt = len+1;
    UCB1I2CSA = (0xA0 >> 1);
    UCB1IE |= UCTXIE0;
    UCB1CTLW0 |= UCTXSTT;
}

void mem_read(uint16_t eeprom_addr, float *buf, int len)
{
   // bytes_transmitted = 0;
    buf[0]=eeprom_addr>>8;
    buf[1]=eeprom_addr;//& 0xFF;
    g_buf = buf;
    rx_byte_cnt = len;
    tx_byte_cnt = 0;
    UCB1I2CSA = (0xA0 >> 1);
    UCB1IE |= UCTXIE0;
    UCB1CTLW0 |= UCTXSTT;
}

int main(void) {
//    char arr[5]="Hello";
    float arr[15]={0x00, 0x50,22.555656};
    unsigned int x = 0x0050;
    WDTCTL = WDTPW | WDTHOLD; // Stop the watchdog timer
    PM5CTL0 = ENABLE_PINS;    // Unlock pins

    UCB1CTLW0 |= UCSWRST;

    UCB1CTLW0 |= UCSSEL_3;
    UCB1BRW = 80; // Set clock divider for desired SCL frequency

    UCB1CTLW0 |= UCMODE_3;
    UCB1CTLW0 |= UCMST | UCSYNC;
    UCB1CTLW0 |= UCTR;
    UCB1I2CSA = (0xA0 >> 1);

    // Configure I2C pins
    P8SEL1 &= ~(BIT5 | BIT6);
    P8SEL0 |= (BIT5 | BIT6);

    PM5CTL0 &= ~LOCKLPM5;

    UCB1CTLW0 &= ~UCSWRST;

    //UCB1IFG = 0;
  //  UCB1IE |= UCTXIE0;

    __enable_interrupt();
    mem_write(x, arr, 15);
    __delay_cycles(200000);
    mem_read(0x0050, &data_in, 3);
    while(1);

    return 0;
}

// I2C ISR
#pragma vector = EUSCI_B1_VECTOR
__interrupt void EUSCI_B1_I2C_ISR(void)
{
    static uint8_t mode = 0;
    switch (__even_in_range(UCB1IV, USCI_I2C_UCBIT9IFG)) // Corrected to use UCB1IV
    {
        case USCI_I2C_UCNACKIFG: // NACK interrupt
            break;
        case USCI_I2C_UCALIFG:   // Arbitration Lost interrupt
            break;
        case USCI_I2C_UCSTTIFG:  // Start bit interrupt
            break;
        case USCI_I2C_UCSTPIFG:  // Stop bit interrupt
            break;
        case USCI_I2C_UCRXIFG0:   // Receive buffer full interrupt
            data_in[bytes_received++] = UCB1RXBUF; // Read received data
            rx_byte_cnt--;

            if(rx_byte_cnt==1) {
               // UCB1CTLW0 |= UCTXNACK;
                UCB1CTLW0 |= UCTXSTP;
                mode = 0;
                g_buf = 0;  // break point for read
            }
            break;

        case USCI_I2C_UCTXIFG0:
            if(tx_byte_cnt /*&& (bytes_transmitted>1)*/) {

                UCB1TXBUF = *g_buf;
                g_buf++;
                tx_byte_cnt--;
                if(tx_byte_cnt==0) {
                    UCB1CTLW0 |= UCTXSTP;
                    //addr=0;
                    g_buf = 0;     // break point to see write
                }
            }

            if(rx_byte_cnt)
            {
                if(mode == 0 || mode == 1) {
                    UCB1TXBUF = *g_buf;
                    g_buf++;
                    mode++;
                }
                else {
                    // End of EEPROM address transmission, initiate read operation
                    bytes_received = 0;
                    UCB1CTLW0 &= ~UCTR; // Switch to RX mode
                    UCB1IE &= ~UCTXIE0;
                    UCB1IE |= UCRXIE0;
                    UCB1CTLW0 |= UCTXSTT; // Initiate start condition for read operation
                }
            }


            break;
        default:
            break;
    }

}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    这里有一种解决方案、您可以将浮点数据转换为定点数据、然后发送定点数据。 接收器会将定点数据转换回浮点数据。  

    此处可以使用_iq 定点格式数据。 您可以参考此链接以更好地理解它。   https://www.ti.com/tool/MSP-IQMATHLIB

    此致、

    现金豪

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    请记住、sizeof (float)不是1。

    您应该使用联合体或类似的方法将 float 转换为字节。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    UNION 在 MSP430中如何工作可以获得任何示例或逻辑吗? 或其他什么来帮助我..

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    这是标准 C:

    https://www.learn-c.org/en/Unions

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    另一种方法是使用指针:

    float arr[3]={0x00、0x50、22.555656};

    顺便说一下、0x50不一定是有效的浮点数。

    * uint8_t 字节;

    字节=(uint8_t *)&arr[0];

    用于(int i=0;i< 3* sizeof (float);i++)

    {

        TXDATA =字节++;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    #include <msp430.h>
    #include <stdint.h>
    
    #define ENABLE_PINS 0xFFFE
    #define DATA_SIZE 50 // Number of bytes to read
    //unsigned int addr = 0;
    unsigned int tx_byte_cnt = 0;
    unsigned int rx_byte_cnt = 0;
    float *g_buf = 0;
    char data_in[DATA_SIZE] = {0};
    volatile uint8_t bytes_received = 0;
    volatile uint8_t eeprom_address = 0; // Starting EEPROM address
    
    void floatToHex(float num, uint8_t *hex) {
        // Pointer to access the float as bytes
        uint8_t *ptr = (uint8_t *)&num;
        int i;
        // Extracting the bytes of the float number and storing as hexadecimal bytes
        for ( i = 0; i < 4; i++) {
            // Account for endianness; MSP430 is little-endian
            int index = 3 - i;
    
            // Store high nibble
            hex[i * 2] = (ptr[index] >> 4) & 0x0F;
    
            // Store low nibble
            hex[i * 2 + 1] = ptr[index] & 0x0F;
        }
    }
    
    void mem_write(unsigned int eeprom_addr, float *buf, int len)
    {
        uint8_t hex[8]; // Enough to store the hexadecimal representation of a float
        floatToHex(*buf, hex);
        //bytes_transmitted = 0;
       // addr = eeprom_addr;
        g_buf = buf;
        rx_byte_cnt = 0;
        tx_byte_cnt = len+1;
        UCB1I2CSA = (0xA0 >> 1);
        UCB1IE |= UCTXIE0;
        UCB1CTLW0 |= UCTXSTT;
    }
    
    void mem_read(uint16_t eeprom_addr, float *buf, int len)
    {
       // bytes_transmitted = 0;
        buf[0]=eeprom_addr>>8;
        buf[1]=eeprom_addr;//& 0xFF;
        g_buf = buf;
        rx_byte_cnt = len;
        tx_byte_cnt = 0;
        UCB1I2CSA = (0xA0 >> 1);
        UCB1IE |= UCTXIE0;
        UCB1CTLW0 |= UCTXSTT;
    }
    
    int main(void) {
    //    char arr[5]="Hello";
        float arr[7]={0x00, 0x50,22.55};
    
        unsigned int x = 0x0050;
        WDTCTL = WDTPW | WDTHOLD; // Stop the watchdog timer
        PM5CTL0 = ENABLE_PINS;    // Unlock pins
    
        UCB1CTLW0 |= UCSWRST;
    
        UCB1CTLW0 |= UCSSEL_3;
        UCB1BRW = 80; // Set clock divider for desired SCL frequency
    
        UCB1CTLW0 |= UCMODE_3;
        UCB1CTLW0 |= UCMST | UCSYNC;
        UCB1CTLW0 |= UCTR;
        UCB1I2CSA = (0xA0 >> 1);
    
        // Configure I2C pins
        P8SEL1 &= ~(BIT5 | BIT6);
        P8SEL0 |= (BIT5 | BIT6);
    
        PM5CTL0 &= ~LOCKLPM5;
    
        UCB1CTLW0 &= ~UCSWRST;
    
        //UCB1IFG = 0;
      //  UCB1IE |= UCTXIE0;
    
        __enable_interrupt();
        mem_write(x, arr, 5);
        __delay_cycles(200000);
        mem_read(0x0050, &data_in, 3);
        while(1);
    
        return 0;
    }
    
    // I2C ISR
    #pragma vector = EUSCI_B1_VECTOR
    __interrupt void EUSCI_B1_I2C_ISR(void)
    {
        static uint8_t mode = 0;
        switch (__even_in_range(UCB1IV, USCI_I2C_UCBIT9IFG)) // Corrected to use UCB1IV
        {
            case USCI_I2C_UCNACKIFG: // NACK interrupt
                break;
            case USCI_I2C_UCALIFG:   // Arbitration Lost interrupt
                break;
            case USCI_I2C_UCSTTIFG:  // Start bit interrupt
                break;
            case USCI_I2C_UCSTPIFG:  // Stop bit interrupt
                break;
            case USCI_I2C_UCRXIFG0:   // Receive buffer full interrupt
                data_in[bytes_received++] = UCB1RXBUF; // Read received data
                rx_byte_cnt--;
    
                if(rx_byte_cnt==1) {
                   // UCB1CTLW0 |= UCTXNACK;
                    UCB1CTLW0 |= UCTXSTP;
                    mode = 0;
                    g_buf = 0;  // break point for read
                }
                break;
    
            case USCI_I2C_UCTXIFG0:
                if(tx_byte_cnt /*&& (bytes_transmitted>1)*/) {
    
                    UCB1TXBUF = *g_buf;
                    g_buf++;
                    tx_byte_cnt--;
                    if(tx_byte_cnt==0) {
                        UCB1CTLW0 |= UCTXSTP;
                        //addr=0;
                        g_buf = 0;     // break point to see write
                    }
                }
    
                if(rx_byte_cnt)
                {
                    if(mode == 0 || mode == 1) {
                        UCB1TXBUF = *g_buf;
                        g_buf++;
                        mode++;
                    }
                    else {
                        // End of EEPROM address transmission, initiate read operation
                        bytes_received = 0;
                        UCB1CTLW0 &= ~UCTR; // Switch to RX mode
                        UCB1IE &= ~UCTXIE0;
                        UCB1IE |= UCRXIE0;
                        UCB1CTLW0 |= UCTXSTT; // Initiate start condition for read operation
                    }
                }
    
    
                break;
            default:
                break;
        }
    
    }
    


    我喜欢这个,它仍然写入我的整数部分22.55我不能写我的小数部分为十六进制。


    有什么建议吗?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    #include <msp430.h>
    #include <stdint.h>
    
    #define ENABLE_PINS 0xFFFE
    #define DATA_SIZE 50 // Number of bytes to read
    //unsigned int addr = 0;
    unsigned int tx_byte_cnt = 0;
    unsigned int rx_byte_cnt = 0;
    float *g_buf = 0;
    char data_in[DATA_SIZE] = {0};
    volatile uint8_t bytes_received = 0;
    volatile uint8_t eeprom_address = 0; // Starting EEPROM address
    
    void floatToHex(float num, uint8_t *hex) {
        // Pointer to access the float as bytes
        uint8_t *ptr = (uint8_t *)&num;
        int i;
        // Extracting the bytes of the float number and storing as hexadecimal bytes
        for ( i = 0; i < 4; i++) {
            // Account for endianness; MSP430 is little-endian
            int index = 3 - i;
    
            // Store high nibble
            hex[i * 2] = (ptr[index] >> 4) & 0x0F;
    
            // Store low nibble
            hex[i * 2 + 1] = ptr[index] & 0x0F;
        }
    }
    
    void mem_write(unsigned int eeprom_addr, float *buf, int len)
    {
        uint8_t hex[8]; // Enough to store the hexadecimal representation of a float
        floatToHex(*buf, hex);
        //bytes_transmitted = 0;
       // addr = eeprom_addr;
        g_buf = buf;
        rx_byte_cnt = 0;
        tx_byte_cnt = len+1;
        UCB1I2CSA = (0xA0 >> 1);
        UCB1IE |= UCTXIE0;
        UCB1CTLW0 |= UCTXSTT;
    }
    
    void mem_read(uint16_t eeprom_addr, float *buf, int len)
    {
       // bytes_transmitted = 0;
        buf[0]=eeprom_addr>>8;
        buf[1]=eeprom_addr;//& 0xFF;
        g_buf = buf;
        rx_byte_cnt = len;
        tx_byte_cnt = 0;
        UCB1I2CSA = (0xA0 >> 1);
        UCB1IE |= UCTXIE0;
        UCB1CTLW0 |= UCTXSTT;
    }
    
    int main(void) {
    //    char arr[5]="Hello";
        float arr[7]={0x00, 0x50,22.55};
    
        unsigned int x = 0x0050;
        WDTCTL = WDTPW | WDTHOLD; // Stop the watchdog timer
        PM5CTL0 = ENABLE_PINS;    // Unlock pins
    
        UCB1CTLW0 |= UCSWRST;
    
        UCB1CTLW0 |= UCSSEL_3;
        UCB1BRW = 80; // Set clock divider for desired SCL frequency
    
        UCB1CTLW0 |= UCMODE_3;
        UCB1CTLW0 |= UCMST | UCSYNC;
        UCB1CTLW0 |= UCTR;
        UCB1I2CSA = (0xA0 >> 1);
    
        // Configure I2C pins
        P8SEL1 &= ~(BIT5 | BIT6);
        P8SEL0 |= (BIT5 | BIT6);
    
        PM5CTL0 &= ~LOCKLPM5;
    
        UCB1CTLW0 &= ~UCSWRST;
    
        //UCB1IFG = 0;
      //  UCB1IE |= UCTXIE0;
    
        __enable_interrupt();
        mem_write(x, arr, 5);
        __delay_cycles(200000);
        mem_read(0x0050, &data_in, 3);
        while(1);
    
        return 0;
    }
    
    // I2C ISR
    #pragma vector = EUSCI_B1_VECTOR
    __interrupt void EUSCI_B1_I2C_ISR(void)
    {
        static uint8_t mode = 0;
        switch (__even_in_range(UCB1IV, USCI_I2C_UCBIT9IFG)) // Corrected to use UCB1IV
        {
            case USCI_I2C_UCNACKIFG: // NACK interrupt
                break;
            case USCI_I2C_UCALIFG:   // Arbitration Lost interrupt
                break;
            case USCI_I2C_UCSTTIFG:  // Start bit interrupt
                break;
            case USCI_I2C_UCSTPIFG:  // Stop bit interrupt
                break;
            case USCI_I2C_UCRXIFG0:   // Receive buffer full interrupt
                data_in[bytes_received++] = UCB1RXBUF; // Read received data
                rx_byte_cnt--;
    
                if(rx_byte_cnt==1) {
                   // UCB1CTLW0 |= UCTXNACK;
                    UCB1CTLW0 |= UCTXSTP;
                    mode = 0;
                    g_buf = 0;  // break point for read
                }
                break;
    
            case USCI_I2C_UCTXIFG0:
                if(tx_byte_cnt /*&& (bytes_transmitted>1)*/) {
    
                    UCB1TXBUF = *g_buf;
                    g_buf++;
                    tx_byte_cnt--;
                    if(tx_byte_cnt==0) {
                        UCB1CTLW0 |= UCTXSTP;
                        //addr=0;
                        g_buf = 0;     // break point to see write
                    }
                }
    
                if(rx_byte_cnt)
                {
                    if(mode == 0 || mode == 1) {
                        UCB1TXBUF = *g_buf;
                        g_buf++;
                        mode++;
                    }
                    else {
                        // End of EEPROM address transmission, initiate read operation
                        bytes_received = 0;
                        UCB1CTLW0 &= ~UCTR; // Switch to RX mode
                        UCB1IE &= ~UCTXIE0;
                        UCB1IE |= UCRXIE0;
                        UCB1CTLW0 |= UCTXSTT; // Initiate start condition for read operation
                    }
                }
    
    
                break;
            default:
                break;
        }
    
    }
    


    我喜欢这个,它仍然写入我的整数部分22.55我不能写我的小数部分为十六进制。


    有什么建议吗?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您如何确定 浮点数的值?

    忘记了 EEPROM、只需编写一些创建字节数组的代码、然后恢复值即可。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    确保发送到 EEPROM 的内容是得到的内容。 您也可以在没有 EEPROM 的情况下*运行仿真:

    #include <msp430.h>
    #include <stdint.h>
    
    union floatparts
    {
        float flt;
        uint8_t bytes[sizeof(float)];
    };
    
    int main(void)
    {
        union floatparts fp;
        union floatparts fp2;
        uint8_t pieces[sizeof(float)];
        uint8_t parts[sizeof(float)];
        int i;
        float backtogether;
    
        WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
    
        P1OUT &= ~BIT0;      // Clear P1.0 output latch for a defined power-on state
        P1DIR |= BIT0;                          // Set P1.0 to output direction
    
        PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
                              // to activate previously configured port settings
    
        while (1)
        {
            P1OUT ^= BIT0;                      // Toggle P1.0 using exclusive-OR
            __delay_cycles(100000);             // Delay for 100000*(1/MCLK)=0.1s
    
            fp.flt = 3.1415;
    
            for (i = 0; i < sizeof(float); i++)
            {
                pieces[i] = fp.bytes[i];
            }
            
            // Simulate round trip to EEPROM
    
            for (i = 0; i < sizeof(float); i++)
            {
                parts[i] = pieces[i];
            }
    
            for (i = 0; i < sizeof(float); i++)
            {
                fp2.bytes[i] = parts[i];
            }
    
        backtogether = fp2.flt;
    }
    
    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    如何确定 浮点值?

    根据我的代码 Im、在数组中确定它为浮点  


     float arr[7]={0x00、0x50、22.55};


    第3个值应该转换为  

    void mem_write(unsigned int eeprom_addr, float *buf, int len)
    {
    uint8_t hex[8]; // Enough to store the hexadecimal representation of a float
    
    floatToHex(*buf, hex);
    }
    int main(void)
    
    {
    
    
    float arr[7]={0x00, 0x50,22.55};
    
     mem_write(x, arr, 5);
    }

    如果我这么做、它是否有效?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    确保发送到 EEPROM 的内容是得到的内容。 您也可以在没有 EEPROM 的情况下*运行仿真:

    [/报价]

    它可以在没有 EEPROM 的情况下工作、我甚至为此编写了一个单独的代码、但在将其与 EEPROM 集成时、它只写入浮点的整数部分  
    我希望以十六进制表示、以便在我的逻辑分析仪中查看

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我不知道您使用十六进制数组进行传输的位置。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    捕获了十六进制值22.55、但为4个字节  
    第1个和第2个字节应该是地址低字节和高字节、我还需要做什么?

    void floatToHex(float num, uint8_t *hex)
    {
        // Pointer to access the float as bytes
        unsigned char *ptr = (unsigned char *)&num;
        int i;
        // Extracting the bytes of the float number and storing as hexadecimal bytes
        for ( i = 0; i < 4; i++)
        {
            // Account for endianness; MSP430 is little-endian
            int index = 3 - i;
            // Store high nibble
            hex[i] = (ptr[index] >> 4) & 0x0F;
            // Shift low nibble to position and combine with high nibble
            hex[i] = (hex[i] << 4) | (ptr[index] & 0x0F);
        }
    }
    void mem_write(unsigned int eeprom_addr, float *buf, int len)
    {
        // Convert the float value to its hexadecimal representation
           //union floatparts float_union;
        //   floatToHex(*buf, float_union.bytes);
    
           // Write the EEPROM address first
           buf[0] = eeprom_addr >> 8; // High byte
           buf[1] = eeprom_addr & 0xFF; // Low byte
    
           // Write the float value
         //  for (int i = 0; i < sizeof(float); i++) {
          //     g_buf[i + 2] = float_union.bytes[i];
         //  }
    
        g_buf = buf;
        rx_byte_cnt = 0;
        tx_byte_cnt = len+1;
        UCB1I2CSA = (0xA0 >> 1);
        UCB1IE |= UCTXIE0;
        UCB1CTLW0 |= UCTXSTT;
    }
     float value = 22.55;
        uint8_t hex_representation[8]; // 4 bytes for float -> 8 hex digits
    
        // Convert float value to hexadecimal representation
        floatToHex(value, hex_representation);
    
        unsigned int x = 0x0050;
    
        float arr[sizeof(float)];
        // Place the EEPROM address and converted float value into the buffer
           int i;
           for (i = 0; i < sizeof(float); i++)
           {
               arr[i] = hex_representation[i];
            //   arr[i+2] = hex_representation[i];
           }
             mem_write(x,arr, sizeof(float)); // Pass the address of arr[0] and arr[1] to mem_write
    }         

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    在 floatToHex ()中将浮点值转换为十六进制值时遇到的所有麻烦,但是将其存储在一个浮点数组中呢?

    ar[i]= hex_presentation [i];

    EEPROM 应该只能看到字节、它不关心这些字节是什么。 只有当您从 EEPROM 取回字节时、才应将字节转换为任何字节。

    此外、将它们转换为半字节似乎是浪费 EEPROM、为什么不只发送字节呢?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    在 floatToHex ()中将浮点值转换为十六进制值时遇到的所有麻烦,但是将其存储在一个浮点数组中呢?

    ar[i]= hex_presentation [i];

    [/报价]

    如果我没有存储并直接发送字节、则在逻辑分析仪中的所有字节中仅写入0xFF。
    这就是为什么我这样做。  

    此外,将它们转换为半字节似乎是浪费 EEPROM,为什么不只是发送字节?

    为了实现浮点、我只想写入4个字节、这样我就直接发送它没有写入的字节  

    [/quote]
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    正如我说过的、您确实需要后退一步、将其分解成多个较小的部分并使每个部分正常工作。

    不要只是在问题上轻率地把事情抛到一边来帮助它。

    1.编写一个程序、获取 uint8_t 字节数组并将其发送到 EEPROM、从 EEPROM 读取数据、并验证您发送的数据是否为所读取的数据。 验证您的逻辑分析仪可以看到这些字节。

    2.添加将单个浮点数拆分成字节的能力。

    3.将这些字节发送到 EEPROM。 此时如果得到0xFF、找出原因。