Buffer for Store answer og GSM Shield

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
antoniolinux
Posts: 38
Joined: Thu Dec 19, 2013 12:59 pm

Buffer for Store answer og GSM Shield

Post by antoniolinux »

Hi to all i have this strange situetion, i use GSM Shield if i use this code all work well, i use AT commnad for to use GSM shield

Code: Select all

#include "ch.h"
#include "hal.h"
#include "chprintf.h"

/* Periodic thread for reading data */

static THD_WORKING_AREA(waRead, 128);
static THD_FUNCTION(Thread,arg) {
  (void)arg;
    chRegSetThreadName("thread_callback");

    while (TRUE){
        /* This will wait for a character to be received */
        uint8_t c = sdGet(&SD1); //get the caracter
        sdPut(&SD2, c);  //  put the caracter on sd2

    }
}
.....
  halInit();
  chSysInit();

 
  char AT[] = "AT\r";  // AT COMMAND
  while (true) {

    sdWrite(&SD1, (uint8_t *) AT,3); // va bene
    }
}



All Work Well, if i use this code don't work, i can't store the answer gsm shield this is the code:

Code: Select all

#define BUFFER_SIZE 128
static char bufferMsg[BUFFER_SIZE];

static THD_WORKING_AREA(waRead2, 128);
static THD_FUNCTION(Thread2,arg) {
  (void)arg;
  int  count=0;
    chRegSetThreadName("thread_callback_2");
    while((bufferMsg[count] = sdGet(&SD1)) != '\n' && count < BUFFER_SIZE) { 
     bufferMsg[count]=(char)sdGet(&SD1);
            count++;
          }
}

/*print buffer*/
void printBuffer(char bufferMsg[])
{
  int  count=0;
  while((bufferMsg[count] != '\n') && (count < BUFFER_SIZE)){
   sdPut(&SD2,(uint8_t)bufferMsg[count]);
    count++;
  }

}

....

  while (true) {
    sdWrite(&SD1, (uint8_t *) AT,3); //AT Command

    chThdSleepMilliseconds(3000);
    printBuffer(bufferMsg);

...
}

can you help me?
best regards.
A.
antoniolinux
Posts: 38
Joined: Thu Dec 19, 2013 12:59 pm

Re: Buffer for Store answer og GSM Shield

Post by antoniolinux »

Hi to all, i fix it, i'm my error , i use

Code: Select all

static  uint8_t bufferMsg[BUFFER_SIZE];

and i store the answer in this buffer and later i control if i have a error.
Post Reply