Serial Communication
Posted: Thu Apr 24, 2014 6:01 am
Hi to all,
I want to know what is the time restriction for using chSequentialStreamWrite function, I am using the next code, when I put a chThdSleepMilliseconds < 600ms the frame is truncated:
Thanks a lot,
I want to know what is the time restriction for using chSequentialStreamWrite function, I am using the next code, when I put a chThdSleepMilliseconds < 600ms the frame is truncated:
Code: Select all
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include <stdio.h>
#include <string.h>
#include "chconf.h"
static int8_t flag = 1;
uint8_t DI = 0, DO1 = 0, DOE=0;
uint16_t DI1E=0,DO=0;
uint16_t AI1=0, AI2=0, AI3=0, AI4=0;
char message[10];
char receive;
struct frame {
uint16_t AInput1;
uint16_t AInput2;
uint16_t AInput3;
uint16_t AInput4;
uint8_t DInput;
uint8_t state;
} values;
/* Digital Inputs*/
static void extcb1(EXTDriver *extp, expchannel_t channel) {
static VirtualTimer vt4;
(void)extp;
(void)channel;
if(flag)
flag = 0;
else
flag = 1;
}
static const EXTConfig extcfg = {
{
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOE, extcb1},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
}
};
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
/*
* Activates the serial driver 1 using the driver default configuration.
*/
sdStart(&SD1, NULL);
extStart(&EXTD1, &extcfg);
/*
* Initializes the ADC driver 1 and enable the thermal sensor.
* The pin PC1 on the port GPIOC is programmed as analog input.
*/
//adcStart(&ADCD1, NULL);
//adcSTM32EnableTSVREFE();
palSetGroupMode(GPIOC, PAL_PORT_BIT(0) | PAL_PORT_BIT(1) | PAL_PORT_BIT(2) | PAL_PORT_BIT(3),0,PAL_MODE_INPUT_ANALOG);
//palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG);
palClearPad(GPIOE, GPIOE_DO1);
palClearPad(GPIOE, GPIOE_DO2);
palClearPad(GPIOE, GPIOE_DO3);
palClearPad(GPIOE, GPIOE_DO4);
while (TRUE) {
if (flag) {
DI1E = palReadPort(GPIOE);
DI = ((DI1E & 0x7C)>>2) | (DI1E & 0x80) | ((DI1E & 0x3000)>>7);
values.DInput = DI;
}
else
{
DO = palReadPort(GPIOE);
DOE = (DO & 0xF00)>>4;
}
memcpy(message, &values, sizeof (values));
chSequentialStreamWrite((BaseSequentialStream *)&SD1, (const uint8_t *)&message, sizeof (values));
chThdSleepMilliseconds(600);
}
}Thanks a lot,