Re: MSP430G2452 и SD карта
Добавлено: Пн июн 24, 2013 22:06:50
Да просто потому что только массив и получается в память записать))
Код: Выделить всё
uint8_t test[SIZE];
...
test[0]=inByte;
...
Flash.write(flash+key,test,SIZE);
...
Код: Выделить всё
array[i]Код: Выделить всё
(array_type)(*(array+i*sizeof(array_type)))
так писать нельзя, обязательно должно быть написанно (unsigned char*), в ином случае компилятор ругается и говорит, что перед отправкой в память надо значение перевести в char, (unsigned char*) вод эта штук и переводит как разFlash.write(flash+key,test,SIZE);
Скиньте заголовочный файл, в котором объявлена эта самая Flash.write(...).27 скину всю информацию из программы
Provide access to the MSP430 flash memory controller.
All flash memory can be read, erased and written (except SEGMENT_A, the LOCK bits are not in the code, for a good reason).
Flash can only be erased per 512 byte segments (except the 4 special information segments, they are 64 bytes in size)
The same flash locations can be written multiple times with new values, but flash bits can only be reset (from 1 to 0) and cannot
change to a 1 (you need to flash erase the whole segment)
functions:
~~~~~~~~~~
erase(): Erase a flash segment, all bytes in the segment will read 0xFF after an erase
read(): Read flash locations (actually just a proxy for memcpy)
write(): Write flash locations (actually just a proxy for memcpy), the same location can be written multiple times,
but once a bit is reset, you cannot set it with a subsequent write, you need to flash the complete segment to do so.
constants:
~~~~~~~~~~
SEGMENT_A // pointer to 64 byte flash segments
SEGMENT_B
SEGMENT_C
SEGMENT_D
Macros:
~~~~~~~
SEGPTR(x) // Return pointer to first complete segment inside variable
SEGMENT(n) // Return pointer to start of segment n (n=0..63)
NOTE: you are flashing the program memory, you can modify EVERYTHING (program, data) this is usually not what you want.
Be carefull when flashing data. You may use SEG_B to SEG_D for normal use, they should not be filled by the compiler
If you wish to use main memory, you need to inform the linker NOT to use the segments you wish to use in the linker script
(this is not for the faint of heart).
An alternative approach is to allocate a static variable with a size of AT LEAST 2 SEGMENTS in your program.
This makes sure there is at least ONE COMPLETE SEGMENT in this static variable, so there is no colleteral damage when you flash this
area. You need to find the pointer to the start of the next segment. There is a macro define to do this: SEGPTR(x)
A example that makes 2 segments available for flashing by allocating 3 segments of constant data:
Using the example:
~~~~~~~~~~~~~~~~~~
On the launchpad; put the two UART jumpers in HARDWARE SERIAL position (horizontal position) and use the terminal window to connect
to the board (9600baud).
'e' Erase the flash segment
'w' Write "Hello World" to the flash
'r' Read the contents of the flash, and print as byte values and characters. stop at the first NULL byte
- When you program the launchpad and read the flash, a single "0" character should be read (mem contains zero values)
Writing the flash before you have erased it is not possible (you cannot program OFF bits to ON bits)
- When you erase the flash, 0xFF values will be read back
- When you write the flash, "Hello World" will be read back
*/
#include "MspFlash.h"
// Two options to use for flash: One of the info flash segments, or a part of the program memory
// either define a bit of constant program memory, and pass a pointer to the start of a segment to the flash functions,
//*** Option 1: use program memory, uncomment these lines and you have 512 bytes of flash available (1024 bytes allocated) ****
//const unsigned char data[2*SEGMENT_SIZE] = {0};
//#define flash SEGPTR(data)
//
//*** Option 2: use one of the 64 byte info segments, uncomment this line. Use SEGMENT_B, SEGMENT_C or SEGMENT_D (each 64 bytes, 192 bytes in total)
#define flash SEGMENT_D
//
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if ( Serial.available() )
{
switch ( Serial.read() )
{
case 'e': doErase(); break;
case 'r': doRead(); break;
case 'w': doWrite(); break;
case 10:
case 13: break;
default: doHelp();
}
}
}
void doRead()
{
unsigned char p = 0;
int i=0;
Serial.println("Read:");
do
{
Flash.read(flash+i, &p, 1);
Serial.write(p);
Serial.print(":");
Serial.println(p);
} while ( p && (i++ < 16) );
Serial.println(".");
}
void doErase()
{
Serial.println("Erase");
Flash.erase(flash);
Serial.println("Done.");
}
void doWrite()
{
Serial.println("Write");
Flash.write(flash, (unsigned char*) "Hello World!" ,13);
Serial.println("Done.");
}
void doHelp()
{
int div = (F_CPU/400000L) & 63;
Serial.println("flash test: e, r, w");
Serial.println(F_CPU);
Serial.println(div);
}
Вот такая ошибка если написатьsketch_jun27a.cpp: In function 'void loop()':
sketch_jun27a.cpp:48:38: error: invalid conversion from 'char' to 'unsigned char*' [-fpermissive]
C:\Users\greatdrek\Desktop\energia-0101E0008\hardware\msp430\libraries\MspFlash/MspFlash.h:77:10: error: initializing argument 2 of 'void MspFlashClass::write(unsigned char*, unsigned char*, int)' [-fpermissive]
Flash.write(flash+key, inByte ,1);
Код: Выделить всё
Flash.write(flash+key, &inByte ,1);
и вообще круто все работает. Спасибо большое вам! Теперь можно код сократить в 20раз.unsigned char inByte=0;
Не за что.Огромнейшее спасибо
Я оставил это Вам.только еще надо было написать
Код: Выделить всё
((unsigned char *) (&inByte))
Но внимание - делая такие фокусы, нужно всегда осознавать возможные последствия.Почти любой, под который не поленитесь написать драйвер. Вопрос в объемах трудозатрат.какой экран подойдет под этот микроконтроллер?
SPI удобен тем, что использует всего четыре вывода МК. Но при желании можно нарастить выходы регистрами...Я так понял что нужен с SPI
Читаю, понял где я тупил. Я просто лучше намного java знаю чем C++, вот и завис.ОБЯЗАТЕЛЬНО почитайте про особенности работы с указателями и разберитесь в этом.
Сделать можно почти все, вопрос зачем. Я же говорил - вопрос в объеме памяти и требуемых усилиях. Цветной дисплей это дополнительные проблемы - в три раза больше памяти, более ресурсоемкие алгоритмы работы с изображением - канала-то три вместо одного. Оно Вам надо?но я хотел цветной дисплей, или цветной не подойдет для msp430?
Еще одна ошибка - путать ANSI C и C++. Это разные вещи. И C++ тут не при чем.Я просто лучше намного java знаю чем C++
Я его начал учить для того, что бы немного понимать с чем мне придется работать когда я куплю себе телефон на Android, потом я программировал на андроид, не не ява язык но синтаксис похож очень, ну и ява продолжал учить, писал свои игры на нем, а С я особо никогда не учил, просто знаю основы с лекций в универе.YS писал(а):Цветной дисплей лучше брать, когда наберетесь опыта с чем попроще.![]()
Ага, java как раз из тех языков, что щадят нежный мозг программиста и изо всех сил скрывают от него природу железа и указатели в частности.