Like the project. I am trying to use my stm32 as display renderer, so I needed to make it as i2c slave and set the Wire pins to I2C2. Arduino nano is sending over i2c letters to put on the display. It doesn't work while it is displaying, only before displaying image. I know that the code relies on hardware timer, so delay, pwm etc doesn't work, but does it also disable i2c and spi interfaces?
#include <Wire.h>
#include "bluevga.h"
#include "font.h" // imports a ASCII Flash font bitmap
#include "bluebitmap.h" // functions for drawing pixels in the screen
#define LED_PIN PB12
BlueVGA vga(ASCII_FONT);
//BlueVGA vga(USE_RAM);
uint8_t color_code = vga.getColorCode(RGB_WHITE, RGB_BLACK);
BlueBitmap fontBitmap(8, 8, (uint8_t *)ASCII_FONT);
volatile char text_buffer[VRAM_HEIGHT][VRAM_WIDTH] = {0};
volatile bool blink_led = true;
static void twi_receive(int bytes);
static void twi_request(void);
void setup() {
Wire.setSCL(PB10);
Wire.setSDA(PB11);
Wire.begin(4);
Wire.onReceive(twi_receive);
Wire.onRequest(twi_request);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
{
uint8_t tx = 0;
uint8_t ty = 0;
for (char letter = 32; letter < 127; letter++)
{
text_buffer[ty][tx++] = letter;
if (tx >= 28)
{
tx = 0;
ty++;
}
}
}
vga.clearScreen(color_code);
}
void loop()
{
BlueBitmap::eraseRamTiles();
for(uint8_t y = 0; y < VRAM_HEIGHT; y++)
{
char* line = (char*)text_buffer[y];
vga.printStr(0, y, color_code, line);
}
if (blink_led)
{
digitalWrite(LED_PIN, HIGH);
vga.waitVSync(60);
digitalWrite(LED_PIN, LOW);
vga.waitVSync(60);
blink_led = false;
}
}
// Write from Master, Read from Slave
static void twi_receive(int bytes)
{
if (bytes != 3)
return;
uint8_t buffer[3];
Wire.readBytes(buffer, 3);
uint8_t x = buffer[0];
uint8_t y = buffer[1];
uint8_t c = buffer[2];
text_buffer[y][x] = c;
blink_led = true;
}
// Read from Master, Write from Slave
static void twi_request(void)
{
}
#include <Arduino.h>
#include <Wire.h>
static void write_vga(uint8_t x, uint8_t y, uint8_t c);
void setup()
{
Wire.begin();
}
void loop()
{
write_vga(0, 0, 'A');
write_vga(1, 0, 'B');
write_vga(2, 0, 'C');
}
static void write_vga(uint8_t x, uint8_t y, uint8_t c)
{
Wire.beginTransmission(4);
Wire.write(x);
Wire.write(y);
Wire.write(c);
Wire.endTransmission();
}