Bonsoir,
je rencontre un pb lorsque j'essaye d'afficher un caractère en temps réel sur l'écran LCD de ma STM32F429I discovery-board. Pour pouvoir affiché un caractère j'utilise l’hyper-terminal Bray avec un driver FT232R qui communique directement avec ma board la première phase du programme fonctionne, si j'envoie un caractère ou une chaîne de caractère depuis le terminal sur la fenêtre de retour je peux lire ce que j'ai envoyé. Ensuite j'ai intégré la bibliothèque LCD pour pouvoir afficher du texte sur l’écran LCD. Cela fonctionne si les chaines de caractères sont prédéfinis voir exemple du main ci-dessous:
Main.c ( avec chaîne de caractère prédéfinis):
Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 int main(void) { uint8_t c; /* Initialize system */ SystemInit(); GLCD_Initialize(); /* GLCD Initialization */ GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetTextColor(Black); GLCD_DisplayString(0, 0, __FI, "Developpez.com"); // ligne 0, colonne 0, Font Index 16x24, chaîne de caractères /* Initialize USART1 at 9600 baud, TX: PB6, RX: PB7 */ TM_USART_Init(USART1, TM_USART_PinsPack_2, 9600); while (1) { /* Get character from internal buffer */ c = TM_USART_Getc(USART1); if (c) { /* If anything received, put it back to terminal */ TM_USART_Putc(USART1, c); } } }
Dans cette configuration sur la première ligne du LCD "Developpez.com" s'affiche et je peux toujours utiliser la fonction hyper-terminal transmit/receive, tout fonctionne.
L'étape suivante est d'implémenter le programme pour que lorsque j'envoie un caractère depuis l'hyper-terminal il s'affiche sur l'écran LCD.
Main.c (implémenter pour afficher un caractère en tps réel):
Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 int main(void) { uint8_t c; /* Initialize system */ SystemInit(); GLCD_Initialize(); /* GLCD Initialization */ GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetTextColor(Black); GLCD_DisplayString(0, 0, __FI, "Developpez.com"); // line 0, column 0, Font Index 16x24, string /* Initialize USART1 at 9600 baud, TX: PB6, RX: PB7 */ TM_USART_Init(USART1, TM_USART_PinsPack_2, 9600); while (1) { /* Get character from internal buffer */ c = TM_USART_Getc(USART1); if (c) { GLCD_DisplayChar(1, 0, __FI, c); /* If anything received, put it back to terminal */ TM_USART_Putc(USART1, c); } } }
Et la ça ne fonctionne pas au lieu de m'afficher le caractère tapé ds la console de l'hyper-terminal, il y a un espèce de gribouillis qui n'a aucune signification à l'emplacement ou devrait être écrit le caractère!
Pour ce que ça intéresse voici la fonction qui récupère le caractère ds le buffer:
Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 uint8_t TM_USART_Getc(USART_TypeDef* USARTx) { int8_t c = 0; TM_USART_t* u = TM_USART_INT_GetUsart(USARTx); /* Check if we have any data in buffer */ if (u->Num > 0 || u->In != u->Out) { /* Check overflow */ if (u->Out == u->Size) { u->Out = 0; } /* Read character */ c = u->Buffer[u->Out]; /* Increase output pointer */ u->Out++; /* Decrease number of elements */ if (u->Num) { u->Num--; } } /* Return character */ return c; }
Et la fonction qui affiche un caractère:
Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 /******************************************************************************* * Disply character on given line * * Parameter: ln: line number * * col: column number * * fi: font index (0 = 6x8, 1 = 16x24) * * c: ascii character * * Return: * *******************************************************************************/ void GLCD_DisplayChar (unsigned int ln, unsigned int col, unsigned char fi, unsigned char c) { c -= 32; switch (fi) { case 0: /* Font 6 x 8 */ GLCD_DrawChar(col * 6, ln * 8, 6, 8, (unsigned char *)&Font_6x8_h [c * 8]); break; case 1: /* Font 16 x 24 */ GLCD_DrawChar(col * 16, ln * 24, 16, 24, (unsigned char *)&Font_16x24_h[c * 24]); break; } }
J'ai constaté qu'en ajoutant un délais avt ou après la fonction d'affichage la lettre frappée ds l'hyper-terminal s'affiche mais seulement le tps du délais après j'ai un rectangle noir qui s'affiche:
Main.c (avec le délais):
Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 int main(void) { uint8_t c; /* Initialize system */ SystemInit(); GLCD_Initialize(); /* GLCD Initialization */ GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetTextColor(Black); GLCD_DisplayString(0, 0, __FI, "Devellopez.com"); // line 0, column 0, Font Index 16x24, string /* Initialize USART1 at 9600 baud, TX: PB6, RX: PB7 */ TM_USART_Init(USART1, TM_USART_PinsPack_2, 9600); while (1) { /* Get character from internal buffer */ c = TM_USART_Getc(USART1); if (c) { GLCD_DisplayChar(1, 0, __FI, c); Delay(100000000); /* If anything received, put it back to terminal */ TM_USART_Putc(USART1, c); } } } void Delay(volatile unsigned int delay) { for (; delay != 0; delay--); }
Si quelqu'un a une idée je suis preneur merci pour votre aide!
Partager