Go Down

Topic: Micro VGA-Text (Read 2 times) previous topic - next topic

P18F4550

I Still cant get the example working!
This Works
Code: [Select]

#include <Spi.h>

void setup()
{
}

void loop()
{
 Spi.transfer(0x41);
}


But the example still does not.
Looking at the Duemilanove Schematic PB0 is digital pin 8 and PB1 is digital pin 9, this is confirmed in the code within arduino_uvga.c
Code: [Select]

  __builtin_avr_delay_cycles(100);
  PORTB &= ~(1<<1); // PORTB1/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);


which must mean these connections are wrong
1 GND -> Arduino GND
2 +5V -> Arduino 5V
3 +3V3  NOT CONNECTED
4 CS# -> Arduino Digital 8
5 SCK -> Arduino Digital 13
6 RDY# -> Arduino Digital 9
7 MISO -> Arduino Digital 12
8 MOSI -> Arduino Digital 11

so which is wrong, the code or connection, either way i cannot get the damn example to work.

P18F4550

OK, as an update to myself and anyone having trouble with microVGA-TEXT, as i suspected arduino_uvga.c is wrong, copy and paste this code into aruuino_uvga.c in hardware\libraries\MicroVGA, save the file and compile either of the examples, the tetris demo is working for me.

Code: [Select]

// 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

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);

}


one more thing, it's not implimented in the example code but pin 13 of uVGA is active LOW reset and needs to be toggled once when you reset arduino,
Let me know if this code works for you.

P18F4550

One final update, all is working well now, after changing the arduino_uvga.c code spi is working, im now reading analog ports and displaying formatted results on a 15" flat screen lcd, sprintf() is a big help for formatting strings, i don't know if or how to post a picture here so i cannot show you.

trober256

Thank you for posting your fix. After rewiring and pasting in your code, both the menu and tetris demos work great.


Here is another thing i came across that may help others:
When trying to compile the microvga demos under the current arduino IDE, I got errors concerning __builtin_avr_delay_cycles

My dumb fix, until i find out how to really get it added was to write this at the top of ardunio_uvga.c:

Code: [Select]

void __builtin_avr_delay_cycles(int numcycles)
{
     while(numcycles)
     {
           numcycles--;
     }
}

P18F4550

#4
Jan 30, 2010, 04:09 pm Last Edit: Jan 30, 2010, 04:27 pm by Funky_Gibbon Reason: 1
Great,
Thanks for letting me know, im glad it's working for someone else,
you may or may not have realised that sending a byte to uVGA displays that bytes ascii character, use sprintf to convert your user data into a formatted string then send with _cputs()

Code: [Select]

//   this is not the complete code, these are the componants required
//   to make a formatted string
#include <stdio.h>  // Required by sprintf()
char buffer [50];     // Output Buffer

// sprintf() in action
sprintf (buffer, "Analog 0 Value = %d    ", analogRead(0) );
_cputs(buffer);  // send the formatted string


You dont have to read the analog port, you could display anything, i find it usefull for debugging and displaying register and port states.
I don't get any errors regarding __builtin_avr_delay_cycles, we might have different setups, im useing a 328 and ide 17

Hope this helps

copabel

I hereby want to add the file for the Arduino Mega...
Code: [Select]
// debugged 25/1/10 by Shaun Ruscoe
// changed 14/03/10 by Copabel for Arduino Mega.

/*
 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            | Arduino Mega Digital 53 (PB0)
5 SCK -> Arduino Digital 13            | Arduino Mega Digital 52
6 RDY# -> Arduino Digital 8            | Arduino Mega Digital 10 (PB4)
7 MISO -> Arduino Digital 12      | Arduino Mega Digital 51
8 MOSI -> Arduino Digital 11      | Arduino Mega Digital 50

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

/*
// Arduino Duemilanove pin definitions

#define DD_MOSI   4
#define DD_MISO   3
#define DD_SCK    5

*/

// Arduino Mega Pin definitions

#define DD_MOSI   2
#define DD_MISO   3
#define DD_SCK    1

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 -> CS#
  PORTB &= ~(1<<0); // PORTB0=0
  __builtin_avr_delay_cycles(100);
   // wait for RDY signal to go low!
  while (PINB & (1<<4) ); // PB4 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
  PORTB |= (1<<0); // PORTB0=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<<PINB0);

  DDRB &= ~(1<<4); // PB4 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);

}


Shura1oplot

All boards are now supported
Fixed Arduino Mega
Fixed undefinded __builtin_avr_delay_cycles function

Code: [Select]

// debugged 25/1/10 by Shaun Ruscoe
// changed 14/03/10 by Copabel for Arduino Mega.
// fixed 16/05/10 by Sh00rGEn

/*
 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      | Arduino Mega Digital 53
5 SCK -> Arduino Digital 13      | Arduino Mega Digital 52
6 RDY# -> Arduino Digital 8      | Arduino Mega Digital 10
7 MISO -> Arduino Digital 12      | Arduino Mega Digital 50
8 MOSI -> Arduino Digital 11      | Arduino Mega Digital 51

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

#ifndef __builtin_avr_delay_cycles
void __builtin_avr_delay_cycles(unsigned long __n) {
   while(__n)
       __n--;
}
#endif

#if defined(__AVR_ATmega1280__)
// Arduino Mega Pin definitions

#define DD_SS     0      // PB0      | Arduino Mega Digital 53
#define DD_MOSI   2      // PB2      | Arduino Mega Digital 51
#define DD_MISO   3      // PB3      | Arduino Mega Digital 50
#define DD_SCK    1      // PB1      | Arduino Mega Digital 52
#define DD_RDY    4      // PB4      | Arduino Mega Digital 10

#else
// Arduino Duemilanove pin definitions

#define DD_SS     2      // PB2      | Arduino Digital 10
#define DD_MOSI   3      // PB3      | Arduino Digital 11
#define DD_MISO   4      // PB4      | Arduino Digital 12
#define DD_SCK    5      // PB5      | Arduino Digital 13
#define DD_RDY    0      // PB0      | Arduino Digital 8

#endif

#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<<DD_SS); // SS#=0
  __builtin_avr_delay_cycles(100);
   // wait for RDY signal to go low!
  while (PINB & (1<<DD_RDY) );
  __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<<DD_SS); // 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<<DD_SS);

  DDRB &= ~(1<<DD_RDY);
  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);

}


Manawyrm

Hello,
sorry for pulling up  :-/

i have bought one module, but it wont work for me,
i got an error with the last code from Shura1oplot
Code: [Select]

G:\Backup\2010.02.16 Vor Windows 7 Installation\Eigene Dateien\Downloads\arduino-0017\arduino-0017\hardware\libraries\MicroVGA\arduino_uvga.c: In function '_putch':

G:\Backup\2010.02.16 Vor Windows 7 Installation\Eigene Dateien\Downloads\arduino-0017\arduino-0017\hardware\libraries\MicroVGA\arduino_uvga.c:158: internal compiler error: in cgraph_estimate_size_after_inlining, at ipa-inline.c:188

Please submit a full bug report,

with preprocessed source if appropriate.

See <URL:http://sourceforge.net/tracker/?atid=520074&group_id=68108&func=browse> for instructions.



Thanks, Tobias Mädel

Go Up