-1

I am trying to store data in the PROGMEM and retrieve it later. Then send them through USB serial comms to screen.

int8_t serial_comm_write(const uint8_t *buffer, uint16_t size){
    //Here contains the code from the lib which I don't understand.
    //Basically, it's sending data (char *data) thru to screen. 
}

//This char *data could simply be:
// char *line = "This is stored in RAM"
//usb_send_info(line); would send the "line" to the screen.
void usb_send_info(char *data){
    serial_comm_write((uint8_t *)data, strlen(data));
}

//This doesn't work. I got a squiggly line saying "unknown register name 
//'r0'
//have no idea what it means. 
void usb_send_info_P(const char *data){
    while(pgm_read_byte(data) != 0x00){
        usb_send_info((pgm_read_byte(data++))); 
    }
}

const static char line1[] PROGMEM = "This is stored in flash mem";

usb_send_info_P(line1);

It just doesn't work. Any tips or alternatives? Cheers.

Jack Hu
  • 43
  • 6

2 Answers2

0

usb_send_info expects a char* that points to SRAM, not the FLASH (PROGMEM).

usb_send_info((pgm_read_byte(data++))); 

pgm_read_byte reads a single byte/char from the given PROGMEM address. It does not return a pointer. So this function call does not make sense.

If you change usb_send_info like this, it should work:

void usb_send_info(char data) {
    serial_comm_write((uint8_t *)&data, 1);
}
Rev
  • 5,827
  • 4
  • 27
  • 51
0

Got some help from a mate. For whoever is wondering, here is the answer to the question. Special thanks to Jonathan.

int8_t serial_comm_transmit(uint8_t c)
{
    uint8_t timeout, intr_state;

    if (!usb_configuration) return -1;

    intr_state = SREG;
    cli();
    UENUM = CDC_TX_ENDPOINT;

    if (transmit_previous_timeout) {
        if (!(UEINTX & (1<<RWAL))) {
            SREG = intr_state;
            return -1;
        }
        transmit_previous_timeout = 0;
    }

    timeout = UDFNUML + TRANSMIT_TIMEOUT;
    while (1) {

        if (UEINTX & (1<<RWAL)) break;
        SREG = intr_state;

        if (UDFNUML == timeout) {
            transmit_previous_timeout = 1;
            return -1;
        }

        if (!usb_configuration) return -1;

        intr_state = SREG;
        cli();
        UENUM = CDC_TX_ENDPOINT;
    }

    UEDATX = c;

    if (!(UEINTX & (1<<RWAL))) UEINTX = 0x3A;
    transmit_flush_timer = TRANSMIT_FLUSH_TIMEOUT;
    SREG = intr_state;
    return 0;
}

void usb_send_info(const char *data){
    for (int i = 0; i < strlen_P(data); i ++){
        serial_comm_transmit(pgm_read_byte(&data[i]));
    }
}

static char line1[] PROGMEM = "This is stored in flash mem";

usb_send_info(line1);
Jack Hu
  • 43
  • 6