The serial driver 1 (SD1) cant receive data

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

Moderator: RoccoMarco

Post Reply
dotaviper
Posts: 10
Joined: Mon Sep 28, 2015 4:44 am
Has thanked: 3 times

The serial driver 1 (SD1) cant receive data

Post by dotaviper »

Hi everybody:
SD1 can send data to serial debugging assistant,but cant received the data send from serial debugging assistant. Here is the code i am running:

Code: Select all

static WORKING_AREA(waCANThread,4096);
static msg_t CANThread(void *arg)
{
   (void)arg;

//   EventListener el;
   BaseChannel *seri=(BaseChannel *)&SD1;//
   static uint8_t smsg[20]={1},*rmsg;
   CANRxFrame rxmsg;
   uint8_t i=0;

   unsigned char txr[8]={0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};//

      while(1)
      {
         msg_t result = canReceive(&CAND1, CAN_ANY_MAILBOX, &rxmsg, TIME_IMMEDIATE);

         if(result==RDY_OK)
         {
            if(rxmsg.EID==0x04000001)
            {
               palTogglePad(GPIOB,9);//
            }
         }

//         palTogglePad(GPIOB, GPIOB_LED_A);

           chSysLock();
           /* The following function must be called from within a system lock zone. */
           size_t bytesAvailable = chnBytesAvailable(seri);
           chSysUnlock();
           smsg[0]=0;smsg[1]=1;smsg[2]=2;

           chnWrite(seri, smsg, 3);
           chThdSleepMilliseconds(1000);
           if(bytesAvailable)//
           {
              smsg[0]=bytesAvailable;smsg[1]=1;smsg[2]=2;
              chnWrite(seri, smsg, 3);//

            palTogglePad(GPIOB,9);
              chnRead(seri, rmsg, bytesAvailable);
              memcpy(txr,rmsg,bytesAvailable);

              palTogglePad(GPIOB,9);
              //EID,DATA,LENGTH
              CANTransmit(0x04000001,txr,bytesAvailable);//send
              chThdSleepMilliseconds(1000);
              bytesAvailable=0;
           }
                    }
          return 0;
}


when I send data to SD1 from serial debugging assistant, why the bytesAvailable always be zero?
thank you very much for your reply.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The serial driver 1 (SD1) cant receive data

Post by Giovanni »

I don't recall ever seeing "chnBytesAvailable()", is it a customization?

Please asks specific questions, putting some random code in a forum post hoping to get solutions almost never works.

Giovanni
Post Reply