Arduino Ethernet with MicroVGA, VGA OK, keyboard not working

Got 2 MicroVGA modules but I can't get them working with my Arduino Ethernet, well sort of. I can run the demo sketches, but keyboard input isn't working and I had to change the library this for it to give image.

// debugged 25/1/10 by Shaun Ruscoe

/*
This file implements low-level routines for Arduino MicroVGA-TEXT.

The MicroVGA has to be configured for SPI mode and connected as follows:

1 GND -> Arduino GND
2 +5V -> Arduino 5V
3 +3V3 NOT CONNECTED
4 CS# -> Arduino Digital 10
5 SCK -> Arduino Digital 13
6 RDY# -> Arduino Digital 8
7 MISO -> Arduino Digital 12
8 MOSI -> Arduino Digital 11

*/
#include "WProgram.h"
#include "conio.h"

// Arduino Duemilanove pin definitions
#define DD_MOSI 3
#define DD_MISO 4
#define DD_SCK 5

#define DDR_SPI DDRB

void SPI_MasterTransmit(char cData)
{
/* Start transmission */
//SPDR = cData;
SPDR = cData;

/* Wait for transmission complete */
while ( ! (SPSR & (1<<SPIF)));

}

#define KEYBUF_SIZE 10
unsigned char keybuf[KEYBUF_SIZE];
unsigned char khead, ktail;

char kbhit;
int _getch()
{
int key;

while (!_kbhit()) ;

key = keybuf[khead];
khead++;
khead %= KEYBUF_SIZE;

if (key == 0) {
key = 0x100 | keybuf[khead];
khead++;
khead %= KEYBUF_SIZE;
}

return key;
}

int _kbhit()
{
if (khead == ktail)
_putch(0);

if (khead == ktail)
return 0;

if (keybuf[khead] == 0 && ((khead+1)%KEYBUF_SIZE) == ktail) {
_putch(0);
if (keybuf[khead] == 0 && ((khead+1)%KEYBUF_SIZE) == ktail)
return 0;
}

return 1;
}

void _putch(char ch)
{
unsigned char response;

__builtin_avr_delay_cycles(100);
PORTB &= ~(1<<2); // PORTB2/SS#=0
__builtin_avr_delay_cycles(100);
// wait for RDY signal to go low!
while (PINB & (1<<0) ); // PB0 is RDY input
__builtin_avr_delay_cycles(100);

/* Start transmission */
//SPDR = cData;
SPDR = ch;

__builtin_avr_delay_cycles(100);

/* Wait for transmission complete */
while ( ! (SPSR & (1<<SPIF)));
__builtin_avr_delay_cycles(100);

response = SPDR;
if (response != 0xFF) {
keybuf[ktail] = response;
ktail++;
ktail %= KEYBUF_SIZE;
kbhit = 1;
}

__builtin_avr_delay_cycles(100);

PORTB |= (1<<2); // PORTB2/SS#=0
}

void microvga_init()
{
kbhit = 0;
khead = 0;
ktail = 0;

/* Set MOSI and SCK output all others input
This agrees to AVR151 Table 1 also */

DDRB = (1<<DD_MOSI) | (1<<DD_SCK) | (1<<PINB2);

DDRB &= ~(1<<0); // PB0 is RDY input
DDRB &= ~(1<<DD_MISO); // MISO is always input

/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0) | (1<<CPHA);

}

Now on the Arduino Ethernet pin 10 = ETHCS maybe this has something to do with it, I've tried changing it to pin 9 but no result, I probably didn't get it right.

Ok found out some more. I have a Arduino Duemilanove too and with an adapted arduino_uvga.c this time by by Sh00rGEn (reply 6) in old forum post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264372292 it works :smiley:

so nothing is broken 8)

but when I plug in my EthernetShield, keyboard inputs aren't working any more. I guess there is some kind of interference between the MicroVGA module and the Ethernet module. MISO - MOSI