Chibios 和 SIM900 Shield

Chibios and the SIM900 Shiled

我有这个问题, 我有 STM32 Nucleo L152RE 和 Shield SIM 900, 现在,如果我写这个简单的线程一切正常,

'static THD_WORKING_AREA(waRead, 128);
    static THD_FUNCTION(Thread,arg) {
     (void)arg;
     chRegSetThreadName("th_callback");
   while (TRUE){
    /* This will wait for a character to be received */
    uint8_t c = sdGet(&SD1); //questo prende il carattere
    sdPut(&SD2, c);  // questo lo spara alla terminale
     } 
    }

' 当我看到一个 AT commnad 时,我看到了好的答案。 现在我创建这个缓冲区

'static  uint8_t bufferMsg[128];'

我用这个线程来存储答案

'    static THD_WORKING_AREA(waRead5, 128);
static THD_FUNCTION(Thread5,arg) {
  chRegSetThreadName("th_Riempio_Buffer");
  msg_t charbuf;
  int count=0;
  uint8_t c;
  event_listener_t Uart1Data;

  eventmask_t flags;
chEvtRegisterMask((event_source_t *)chnGetEventSource(&SD1), &Uart1Data, EVENT_MASK(1));

  while (TRUE) {
       chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
       chSysLock();
       flags =chEvtGetAndClearFlags(&Uart1Data);
      chSysUnlock();
       if (flags & CHN_INPUT_AVAILABLE)
                {
                   do
                   {
                     charbuf = chnGetTimeout(&SD1,TIME_IMMEDIATE);
                      if (charbuf != Q_TIMEOUT)
                             {
                         while((charbuf != '\n') && (count < 128)) {
                           sdWrite(&SD2, (uint8_t *)B3,4); // va bene
                            bufferMsg[count]= charbuf;
                                     count++;
                                   }
                                }
                             }
                   while (charbuf != Q_TIMEOUT);
                }
      }
}
'

这个线程不工作,不存储答案,你能帮我吗?

此致 A.

我用,

定义

#define buffer_size 128
char buffer[buffer_size + 1];
int nbytes = 0;

函数

void SIM_callback(){             /*  GSM900 Serial */
    char x = SIM.getc();   
    buffer[nbytes] = x; 
    nbytes++; if (nbytes > buffer_size) nbytes = buffer_size;
    buffer[nbytes] = '[=11=]';  
}

主要

main (){
    // Clear Buffer 
    buffer[nbytes] = '[=12=]';  
    ...
    while(1);
    ...
}