J'ai acheté un écran lcd qui fonctionne avec la librairie U8glib en mode SPI
Je veux aussi stocker des données sur une cartouche SD...
Sauf que l'appel à la librairie SD provoque l'arrêt de l'affichage sur l'écran.
Dans le code suivant j'obtiens la bonne détection de la cartouche SD et l'affichage de Hello ! mais point de world !
J'utilise un Atmega2560
Qui regarde qu'est-ce qui cloche dans les librairies... C'est trop fort pour moi !
#include <SPI.h>
#include "U8glib.h"
#include <SD.h>
U8GLIB_ST7920_128X64 u8g(52, 51, 48, U8G_PIN_NONE); // Câblage SPI 52/13:E 51/11 R/W MOSI 48/10:RS CS
void draw1(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 22, "Hello!");
}
void draw2(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 44, "World !");
}
#define SERIALBAUD 9600 // pour liaison usb
#define CS_SD 53 // cs pour Uno : 10 et pour mega : 53
#define CS_LCD 48 // cd lcd pour Uno : 9 et mega 48
void setup(void) {
Serial.begin(SERIALBAUD); // liaison usb
pinMode(CS_SD, OUTPUT); // pin CS du lecteur SD
pinMode(CS_LCD, OUTPUT); // pin CS du lCD
u8g.firstPage();
do {
draw1();
} while( u8g.nextPage() );
delay(500);
if (SD.begin(CS_SD)) { // SD detectee ?
Serial.println(" ...carte SD : ok... ");
return;}
}
void loop(void) {
u8g.firstPage();
do {
draw2();
} while( u8g.nextPage() );
delay(500);
Serial.print("a");
}
J'ai acheté un écran lcd qui fonctionne avec la librairie U8glib en mode SPI
Je veux aussi stocker des données sur une cartouche SD...
Sauf que l'appel à la librairie SD provoque l'arrêt de l'affichage sur l'écran.
Bonjour
Je dirais que c'est à priori un comportement nomal
Le SPI gere ses "cibles" en fonction du signal CS
quel pin est utilisé par le CS de l'ecran et le CS de la SD ?
Hello, i meet the problem as same as you , i did as you said, it doesn't work,
is there are any solutions?thanks.
Also , the writer gives the solution, but i can't understand.
can you help me ?
setHardwareBackup
C++/Arduino: void U8GLIB::setHardwareBackup(u8g_state_cb backup_cb)
C: void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb)
Description: The display can be connected to I/O pins which are also shared with other external devices. Examples are SPI, TWI or UART interfaces. Example: SD card and SPI displayshare Clock and Data pins (but have different chip select lines). The SD Card software uses the SPI hardware of the microcontroller to access the SD card, but U8glibshould use a software SPI mode. In such a case, the hardware state of the microcontroller SPI subsystem must be modified before access to SD card and display.This modification is activated by this procedure. Usage is: (1) Init u8glib, (2) call this procedure and (3) init other libraries.Available backup procedures:
u8g_backup_avr_spi: Backup SPI hardware state of an AVR microcontroller.
Arguments:
u8g : Pointer to the u8g structure (C interface only).
backup_cb: Hardware state backup procedure (specific to controller and hardware subsystem).
Returns:
Use: Outside picture loop.
Note: Available in v1.05.
**Example:**U8glib uses software SPI and SD library hardware SPI: