port série rx et tx

Bonjour,

J'envoie des octets à ma carte arduino uno via mon pc sur ubuntu en passant par le port série.
La carte arduino doit allumer des leds en fonction du réseau sur mon PC.
J'ai remarqué que cela fonctionne bien pendant genre 40 secondes puis au bout d'un moment les leds de la arduino RX et TX restent allumées et cela fait n'importe quoi.

Vous pensez que cela vient de quoi?

Cordialement.

Salut

Sans le code cela va être dur d'aider.

@+

ça c'est le code de mon main : #include "Pin.h"#include "General.h"#include "MsTimer2.h"boolean recei - Pastebin.com

celui là c'est là où je gère les leds : #include "Pin.h"#include "GereLedEtat.h"// 3 Leds RGBsvoid GereLedEt - Pastebin.com

Bonjour
En mettant tes codes en pastebin tu te prives des réponses des participants qui pratiquent le forum avec leur smartphone et n'iront pas le télécharger. Privilégier le code , bien formaté, indenté, et intégré au message au moyen des balises appropriées (cf messages épinglés en tête de forum)

le main :

#include "Pin.h"
#include "General.h"
#include "MsTimer2.h"
 
 
boolean received = false;   // Boléen pour connaitre si une donnée est reçue
int tick_time_to_update=0;
byte inByte;
 
  //identifiant de la trame série reçue
  int Identifiant =0;
 
  //variables des états des réseaux
  int wifi =0;
  int ethernet =0;
  int bluetooth =0;
 
  //variable pour stocker les messages série reçues
  int msg[RCVSIZE];
 
  //commande d'alimentation de l'affichage
  char cmd_alimentation_affichage =0;
 
 
void IRQ_tick(void)
{
  static int cpt1 = 0;
  cpt1++;
  if(cpt1 >= TEMPO_200msec)
  {
    tick_time_to_update = 1;
    cpt1 = 0;
  }
 
}
 
void Update(void)
{
  if(received)
 {
  Identifiant = msg[0]; //on définit le premier char provenant de l'udoo comme un identifiant d'une trame série
  switch (1)
        {
            case Identifiant_Alimentation:
                  cmd_alimentation_affichage= msg[1];
                  //GereAlimentation(cmd_alimentation_affichage);
                break;
               
            case 1:
            //Serial.println("update");
                  wifi = msg[0]; // wifi
                  ethernet = msg[1];  //ethernet
                  bluetooth = msg[2]; //bluetooth
                  //Serial.println("wifi avant gereled");
                  //Serial.println(wifi);
                  GereLedEtat(wifi, ethernet, bluetooth);
             break;
                 
            case Identifiant_Alimentation_Led:
                  cmd_alimentation_affichage= msg[1];
                  wifi = msg[2];
                  ethernet = msg[3];
                  bluetooth =msg[4];
                  // GereAlimentation(cmd_alimentation_affichage);
                  GereLedEtat(wifi,ethernet,bluetooth);
                break;
               
            default:
                break;
        }
   }
   received=false;
}
 
 
 
// the setup routine runs once when you press reset:
void setup() {
//initialisation des pins d'entrée analogique des réveils 1 et 2
pinMode(PinReveil1, INPUT);
pinMode(PinReveil2, INPUT);
 
//initialisation des pins de sorties analogiques
pinMode(PinkeepAlive,OUTPUT);
 
//initialisation des Leds
pinMode(Pin_led_wifi_R,OUTPUT);
pinMode(Pin_led_wifi_G,OUTPUT);
 
pinMode(Pin_led_ethernet_R,OUTPUT);
pinMode(Pin_led_ethernet_G,OUTPUT);
 
pinMode (Pin_led_bluetooth_R,OUTPUT);
pinMode (Pin_led_bluetooth_G,OUTPUT);
 
 
//initialisation de l'ensemble des leds
digitalWrite(Pin_led_wifi_R,LOW);
digitalWrite(Pin_led_wifi_G,LOW);
 
digitalWrite(Pin_led_ethernet_R,LOW);
digitalWrite(Pin_led_ethernet_G,LOW);
 
digitalWrite (Pin_led_bluetooth_R,LOW);
digitalWrite (Pin_led_bluetooth_G,LOW);
 
//InitAlimentation();
MsTimer2::set(20,IRQ_tick);
MsTimer2::start();
//initialisation du port série à un baud rate de 115200 bps
Serial.begin(115200);
delay(100);
//Serial.println("start");
 
}
 
void loop() {
 
 
  //variables pour la réception sur le port série
  int count = 0;
 
 
  while (Serial.available() > 0) {
    // get the new byte:
   byte inByte =(byte)Serial.read();
     msg[count] = inByte;
 
    count++;
    received = true;
  } //lecture du port série et remplissage d'un buffer tant qu'il y a des données à lire
    if(tick_time_to_update)
    {
    Update();
    tick_time_to_update =0;
    }
 
delay(10);
 }

le code pour gérer les leds ;

#include "Pin.h"
#include "GereLedEtat.h"
 
// 3 Leds RGBs
 
 
void GereLedEtat(int x_wifi, int x_ethernet, int x_bluetooth )
{
  etat_reseaux wifi = (etat_reseaux) x_wifi;
  etat_reseaux ethernet= (etat_reseaux) x_ethernet;
  etat_reseaux bluetooth = (etat_reseaux) x_bluetooth;
  //conversion de x_wifi,x_ethernet,x_bluetooth en type etat_reseaux, arduino ne prend pas de type enum/struct en paramètre
Serial.println("wifi");
Serial.println(wifi);
 
  switch(wifi)
  {
    case CONNECTE:
 
    digitalWrite(Pin_led_wifi_G,!digitalRead(Pin_led_wifi_G));
    digitalWrite(Pin_led_wifi_R,LOW);
   
    break;
 
    case DECONNECTE:
    digitalWrite(Pin_led_wifi_G,HIGH);
    digitalWrite(Pin_led_wifi_R,LOW);
    break;
 
    case INDISPONIBLE:
    digitalWrite(Pin_led_wifi_R,HIGH);
    digitalWrite(Pin_led_wifi_G,LOW);
    break;
 
    default:
    break;
  }
 
      switch(ethernet)
  {
    case CONNECTE:
    digitalWrite(Pin_led_ethernet_G,!digitalRead(Pin_led_ethernet_G));
    digitalWrite(Pin_led_wifi_R,LOW);
   
    break;
 
    case DECONNECTE:
    digitalWrite(Pin_led_ethernet_G,HIGH);
    digitalWrite(Pin_led_ethernet_R,LOW);
    break;
 
    case INDISPONIBLE:
    digitalWrite(Pin_led_ethernet_R,HIGH);
    digitalWrite(Pin_led_ethernet_G,LOW);
    break;
 
    default:
    break;
  }
 
 
      switch(bluetooth)
  {
    case CONNECTE:
    digitalWrite(Pin_led_bluetooth_G,!digitalRead(Pin_led_bluetooth_G));
    digitalWrite(Pin_led_bluetooth_R,LOW);
   
    break;
 
    case DECONNECTE:
    digitalWrite(Pin_led_bluetooth_G,HIGH);
    digitalWrite(Pin_led_bluetooth_R,LOW);
    break;
 
    case INDISPONIBLE:
    digitalWrite(Pin_led_bluetooth_R,HIGH);
    digitalWrite(Pin_led_bluetooth_G,LOW);
    break;
 
    default:
    break;
  }
 
}

J'ai remarqué que lorsque le moniteur série est ouvert, il n'y a plus aucun problèmes, mais je ne souhaite pas avoir à ce qu'il soit ouvert pour que ça fonctionne.
Ah et pour ouvrir le port série et envoyer des données depuis mon PC j'utilise des appels systèmes comme write()

Une mémoire tampon (buffer) qui sature peut être?

Oui c'est possible j'y ai pensé, mais je n'envoie que 3 chars à un baudrate de 115200
Pourquoi ce buffer ne se vide pas au fur et à mesure ? J'envoie trop vite les données?

voilà comment j'ouvre le port série sur ubuntu

void lecture_port_serie(int fd)
{
    	char buf [200];
	    int n;
    	n = read (fd, buf, sizeof buf); 	// read up to 7 characters if ready to read
	if (n > 0) {
		//printf("quanti: %d\n", n);
		int i;
		for (i = 0; i < n; i++) {
			printf("%c",buf[i]);
		}
	}

}

void set_blocking (int fd, int should_block)
{
        struct termios tty;
        memset (&tty, 0, sizeof tty);
        if (tcgetattr (fd, &tty) != 0)
        {
                printf ("error from tggetattr");
        }

        tty.c_cc[VMIN]  = should_block ? 1 : 0;
        tty.c_cc[VTIME] = 5;            	// 0.5 seconds read timeout

        if (tcsetattr (fd, TCSANOW, &tty) != 0)
                printf ("error setting term attributes");
}

int set_interface_attribs (int fd, int speed, int parity)
{
        struct termios tty;
        memset (&tty, 0, sizeof tty);
        if (tcgetattr (fd, &tty) != 0)
        {
                printf ("error from tcgetattr");
                return -1;
        }

        cfsetospeed (&tty, speed);
        cfsetispeed (&tty, speed);

        tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;     // 8-bit chars
        // disable IGNBRK for mismatched speed tests; otherwise receive break
        // as \000 chars
        tty.c_iflag &= ~IGNBRK;         // ignore break signal
        tty.c_lflag = 0;                // no signaling chars, no echo,
                                        // no canonical processing
        tty.c_oflag = 0;                // no remapping, no delays
        tty.c_cc[VMIN]  = 0;            // read doesn't block
        tty.c_cc[VTIME] = 5;            // 0.5 seconds read timeout

        tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl

        tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
                                        // enable reading
        tty.c_cflag &= ~(PARENB | PARODD);      // shut off parity
        tty.c_cflag |= parity;
        tty.c_cflag &= ~CSTOPB;
        tty.c_cflag &= ~CRTSCTS;

        if (tcsetattr (fd, TCSANOW, &tty) != 0)
        {
                printf ("error %d from tcsetattr", errno);
                return -1;
        }
        return 0;
}

void init_port_serie(void)
{
    char *portname = "/dev/ttyACM0";

	fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
	if (fd < 0)
	{
			printf("error %d opening %s: %s", errno, portname, strerror (errno));
	}

	set_interface_attribs (fd, B115200, 0);		// set speed to 115,200 bps, 8n1 (no parity)
	set_blocking (fd, 0);						// set no blocking

}