Problem accessing large PROGMEM structure


hi,

i'd know if there practical limit size of data structure (array) can store in progmem, or if there known problems once on size.

i working on project using couple of max6960 display driver ics , 8x8 led displays.

i'm using arduino diecimila , hardware spi interface talk max6960 , works fine. able write display , read data without problem.

the display drivers not have built in character generation hardware have created own font , i've stuck in progmem.  i've made custom extended ascii set character 1 255.  each character 8x5 pixels in size, ie 5 bytes of data in big array of 255 such blocks = 1275 bytes.

the problem have getting data out of progmem, more specifically, having problem accessing data beyond character '\' or character value 92 dec (0x5c).  

characters '!' '\' print ok (values 33 dec 92 dec) characters after '\' offset 1, ie 'a' prints 'b' , 'b' prints out 'c' etc.

for example have test code writes following string display "ab[\]ab" , comes out "bc[\^bc".

you can see characters value greater '\' displayed incremented 1.

i have checked font data array , appears correct me, there no repeated character blocks.

the entire character set won't fit here here's how section looks:

code: [select]
prog_uint8_t font_data[end_char - start_char + 1][char_len] = {
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   1 soh
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   2 stx
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   3 etx
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   4 eot
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   5 enq
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   6 ack
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   7 bel
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   8 bs
     {0x00, 0x00, 0x00, 0x00, 0x00}, //   9 ht
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  10 lf
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  11 vt
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  12 ff
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  13 cr
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  14 so
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  15 si
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  16 dle
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  17 dc1
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  18 dc2
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  19 dc3
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  20 dc4
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  21 nak
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  22 syn
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  23 etb
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  24 can
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  25 em
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  26 sub
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  27 esc
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  28 fs
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  29 gs
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  30 rs
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  31 us
     {0x00, 0x00, 0x00, 0x00, 0x00}, //  32 sp
     {0x00, 0x00, 0x00, 0x5e, 0x00}, //  33 !
     {0x00, 0x06, 0x00, 0x06, 0x00}, //  34 "
     {0x14, 0x3e, 0x14, 0x3e, 0x14}, //  35 #
     {0x00, 0x24, 0x6a, 0x2b, 0x12}, //  36 $
     {0x4c, 0x2c, 0x10, 0x68, 0x64}, //  37 %
     {0x34, 0x4a, 0x52, 0x24, 0x10}, //  38 &
     {0x00, 0x00, 0x06, 0x00, 0x00}, //  39 '
     {0x00, 0x00, 0x3c, 0x42, 0x00}, //  40 (
     {0x00, 0x00, 0x42, 0x3c, 0x00}, //  41 )
     {0x00, 0x04, 0x0e, 0x04, 0x00}, //  42 *
     {0x08, 0x08, 0x3e, 0x08, 0x08}, //  43 +
     {0x00, 0x00, 0x40, 0x20, 0x00}, //  44 ,
     {0x00, 0x08, 0x08, 0x08, 0x08}, //  45 -
     {0x00, 0x00, 0x00, 0x20, 0x00}, //  46 .
     {0x00, 0x60, 0x18, 0x06, 0x00}, //  47 /
     {0x00, 0x3c, 0x42, 0x42, 0x3c}, //  48 0
     {0x00, 0x00, 0x04, 0x7e, 0x00}, //  49 1
     {0x00, 0x64, 0x52, 0x52, 0x4c}, //  50 2
     {0x00, 0x42, 0x4a, 0x4a, 0x34}, //  51 3
     {0x00, 0x18, 0x14, 0x7e, 0x10}, //  52 4
     {0x00, 0x4e, 0x4a, 0x4a, 0x32}, //  53 5
     {0x00, 0x3c, 0x4a, 0x4a, 0x32}, //  54 6
     {0x00, 0x02, 0x72, 0x0a, 0x06}, //  55 7
     {0x00, 0x34, 0x4a, 0x4a, 0x34}, //  56 8
     {0x00, 0x4c, 0x52, 0x52, 0x3c}, //  57 9
     {0x00, 0x00, 0x00, 0x24, 0x00}, //  58 :
     {0x00, 0x00, 0x40, 0x24, 0x00}, //  59 ;
     {0x00, 0x00, 0x08, 0x14, 0x22}, //  60 <
     {0x00, 0x14, 0x14, 0x14, 0x14}, //  61 =
     {0x00, 0x22, 0x14, 0x08, 0x00}, //  62 >
     {0x00, 0x04, 0x02, 0x52, 0x0c}, //  63 ?
     {0x00, 0x34, 0x54, 0x64, 0x38}, //  64 @
     {0x00, 0x7c, 0x0a, 0x0a, 0x7c}, //  65 a
     {0x00, 0x7e, 0x4a, 0x4a, 0x34}, //  66 b
     {0x00, 0x3c, 0x42, 0x42, 0x24}, //  67 c
     {0x00, 0x7e, 0x42, 0x42, 0x3c}, //  68 d
     {0x00, 0x3e, 0x4a, 0x4a, 0x42}, //  69 e
     {0x00, 0x7e, 0x0a, 0x0a, 0x02}, //  70 f
     {0x00, 0x3c, 0x42, 0x52, 0x32}, //  71 g
     {0x00, 0x7e, 0x08, 0x08, 0x7e}, //  72 h
     {0x00, 0x00, 0x00, 0x7e, 0x00}, //  73 i
     {0x00, 0x20, 0x40, 0x42, 0x3e}, //  74 j
     {0x00, 0x7e, 0x10, 0x28, 0x46}, //  75 k
     {0x00, 0x3e, 0x40, 0x40, 0x40}, //  76 l
     {0x7e, 0x04, 0x08, 0x04, 0x7e}, //  77 m
     {0x00, 0x7e, 0x04, 0x08, 0x7e}, //  78 n
     {0x00, 0x3c, 0x42, 0x42, 0x3c}, //  79 o
     {0x00, 0x7e, 0x0a, 0x0a, 0x04}, //  80 p
     {0x00, 0x3c, 0x42, 0x22, 0x5c}, //  81 q
     {0x00, 0x7e, 0x12, 0x32, 0x4c}, //  82 r
     {0x00, 0x44, 0x4a, 0x4a, 0x32}, //  83 s
     {0x00, 0x02, 0x7e, 0x02, 0x00}, //  84 t
     {0x00, 0x3e, 0x40, 0x40, 0x3e}, //  85 u
     {0x00, 0x3e, 0x40, 0x20, 0x1e}, //  86 v
     {0x1e, 0x60, 0x18, 0x60, 0x1e}, //  87 w
     {0x00, 0x76, 0x08, 0x08, 0x76}, //  88 x
     {0x00, 0x46, 0x48, 0x48, 0x3e}, //  89 y
     {0x00, 0x62, 0x52, 0x4a, 0x46}, //  90 z
     {0x00, 0x7e, 0x42, 0x00, 0x00}, //  91 [
     {0x00, 0x06, 0x18, 0x60, 0x00}, //  92 \
     {0x00, 0x42, 0x7e, 0x00, 0x00}, //  93 ]
     {0x00, 0x04, 0x02, 0x04, 0x00}, //  94 ^
     {0x00, 0x80, 0x80, 0x80, 0x80}, //  95 _
     {0x00, 0x00, 0x01, 0x02, 0x00}, //  96 `
     {0x00, 0x30, 0x48, 0x28, 0x78}, //  97 a
     {0x00, 0x7e, 0x50, 0x48, 0x30}, //  98 b
     {0x00, 0x30, 0x48, 0x50, 0x00}, //  99 c
     {0x00, 0x30, 0x48, 0x50, 0x7e}, // 100 d
     {0x00, 0x30, 0x68, 0x58, 0x00}, // 101 e
     {0x00, 0x00, 0x7c, 0x0a, 0x00}, // 102 f
     {0x00, 0x18, 0xa4, 0xa8, 0x7c}, // 103 g
     {0x00, 0x7e, 0x10, 0x08, 0x70}, // 104 h
     {0x00, 0x00, 0x74, 0x00, 0x00}, // 105 i
     {0x00, 0x80, 0x88, 0x7a, 0x00}, // 106 j
     {0x00, 0x7e, 0x10, 0x28, 0x40}, // 107 k
     {0x00, 0x00, 0x3e, 0x40, 0x00}, // 108 l
     {0x78, 0x08, 0x70, 0x08, 0x70}, // 109 m
     {0x00, 0x78, 0x10, 0x08, 0x70}, // 110 n
     {0x00, 0x30, 0x48, 0x48, 0x30}, // 111 o
     {0x00, 0xfc, 0x28, 0x24, 0x18}, // 112 p
     {0x00, 0x18, 0x24, 0x28, 0xfc}, // 113 q
     {0x00, 0x78, 0x10, 0x08, 0x10}, // 114 r
     {0x00, 0x4c, 0x54, 0x64, 0x00}, // 115 s
     {0x00, 0x00, 0x3c, 0x48, 0x00}, // 116 t
     {0x00, 0x38, 0x40, 0x20, 0x78}, // 117 u
     {0x00, 0x38, 0x40, 0x20, 0x18}, // 118 v
     {0x38, 0x40, 0x30, 0x40, 0x38}, // 119 w
     {0x00, 0x68, 0x10, 0x68, 0x00}, // 120 x
     {0x00, 0x1c, 0xa0, 0x90, 0x7c}, // 121 y
     {0x00, 0x64, 0x54, 0x4c, 0x00}, // 122 z
     {0x00, 0x08, 0x36, 0x41, 0x00}, // 123 {
     {0x00, 0x00, 0x7f, 0x00, 0x00}, // 124 |
     {0x00, 0x41, 0x36, 0x08, 0x00}, // 125 }
     {0x00, 0x08, 0x04, 0x08, 0x04}, // 126 ~
     {0x00, 0x00, 0x00, 0x00, 0x00}, // 127 del
     {0x00, 0x10, 0x38, 0x54, 0x44}, // 128 ?
     {0x00, 0x00, 0xa0, 0x60, 0x00}, // 129 ,
     {0x00, 0x00, 0xa0, 0x60, 0x00}, // 130 ?
     {0x20, 0x48, 0x3e, 0x09, 0x02}, // 131 ?
     {0xa0, 0x60, 0x00, 0xa0, 0x60}, // 132 ?
     {0x40, 0x00, 0x40, 0x00, 0x40}, // 133 ?
     {0x00, 0x04, 0x3e, 0x04, 0x00}, // 134 ?
     {0x00, 0x14, 0x3e, 0x14, 0x00}, // 135 ?
     {0x00, 0x04, 0x02, 0x04, 0x00}, // 136 ?
     {0x62, 0xb5, 0x4a, 0xa4, 0x42}, // 137 ?
     {0x00, 0x49, 0x56, 0x55, 0x24}, // 138 ?
     {0x00, 0x10, 0x28, 0x44, 0x00}, // 139 ?
     {0x38, 0x44, 0x3c, 0x54, 0x44}, // 140 ?
     {0x00, 0x00, 0x00, 0x00, 0x00}, // 141 ri
     {0x00, 0x65, 0x56, 0x55, 0x4c}, // 142 ?
     {0x00, 0x00, 0x00, 0x00, 0x00}, // 143 ss3
     {0x00, 0x00, 0x00, 0x00, 0x00}, // 144 dcs
     {0x00, 0x00, 0x0a, 0x06, 0x00}, // 145 ?
     {0x00, 0x00, 0x06, 0x0a, 0x00}, // 146 ?
     {0x0c, 0x0a, 0x00, 0x0c, 0x0a}, // 147 ?
     {0x0a, 0x06, 0x00, 0x0a, 0x06}, // 148 ?
     {0x00, 0x00, 0x18, 0x18, 0x00}, // 149 ?
     {0x00, 0x00, 0x10, 0x10, 0x00}, // 150 ?
     {0x00, 0x10, 0x10, 0x10, 0x10}, // 151 ?
     {0x00, 0x04, 0x02, 0x04, 0x02}, // 152 ?
     {0x04, 0x1c, 0x1c, 0x08, 0x1c}, // 153 ?
     {0x00, 0x00, 0x59, 0x6a, 0x01}, // 154 ?
..etc..
     {0x00, 0xfe, 0x28, 0x24, 0x18}, // 254 þ
     {0x00, 0x1a, 0xa0, 0xa2, 0x78}, // 255 ÿ
};


i using standard pgmspace.h library functions access data shown below start_char  = 1, end_char = 255:

code: [select]
unsigned char * copy_char_data(unsigned char c, unsigned char * pos)
{
 unsigned char data = 0;
 if ((c < start_char) || (c >= end_char)) {
   return 0x00;
 }
 return (unsigned char *) memcpy_p(pos, &(font_data[(uint8_t)c - start_char]), 5);
}


i have checked code generating pointer start of each character block in font_data structure , seems generating correct offset array, characters beyond '\'.

in loop () function have following code convert string bitmap font data held in planedata array before sent display driver ic:

code: [select]
i =0;
while (str[i] != 0) {
  copy_char_data((unsigned char) str[i], &planedata[k]);
  k = k + 5;
  i++;
}


this works characters less or equal '\' not characters beyond that, they're off set one.

anyone spot obvious problem or experience similar , know might going on?

is there issue addressing large arrays in progmem?

thanks!

:)

easy fix! problem in c, trailing \ line continuation character.  so line

     {0x00, 0x42, 0x7e, 0x00, 0x00}, //  93 ]

is considered continuation of comment @ end of previous line , therefore ignored.  to demonstrate veracity of analysis, run following simple program , see prints 1, 2, 3, , 5, not 4.

quote
int arr[] =  {
1, // 1
2, // 2
3, // \
4, // 4
5, // 5
};

void setup()
{
 serial.begin(9600);
 for (int i=0; i<sizeof(arr) / sizeof(int); ++i)
   serial.println(arr);
}

void loop(){}


mikal


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Problem accessing large PROGMEM structure


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums