ibrahim03
Full Member level 1
avr studio datatypes
I am trying to write sectors to a mmc card. I am using the following method to write the sectors:
the code works fine for smaller addresses but when the address value exceeds 65535 it 'rolls over'.
I mean if I define
SECTOR = 160 then the address will be calculated as
ADDRESS = SECTOR*512 = 16384 !!
which should be wrong (correct value should be 81920) because I have defined ADDRESS as 'unsigned long' and that should be 32 bits. But why is it acting as 16 bits ?
I am using WINAVR-20050214 and AVR Studio 4.12 to compile my program.I am not using the latest version because with that AVR Studio wont simulate the code with it.
I tried to solve the problem by defining ADDRESS as uint32_t but that was no good either.
I even compiled the code with Imagecraft C compiler ICC AVR but still I had the same problem.
Can anyone please identify the problem over here.How can I (actually) define ADDRESS as a 32 bit number?
I am trying to write sectors to a mmc card. I am using the following method to write the sectors:
Code:
//****************************************************************************************
unsigned char MMC_WRITE_BLOCK( unsigned int SECTOR,unsigned char WRT)
{
unsigned char LPCNT=0;
unsigned long ADDRESS = 0;
ADDRESS=SECTOR*512; //PROBLEM : 'ADDRESS' does not hold a value larger
// than 65535 !!
/*-----------------------CMD24--------------------------------------*/
SPIPORT &= ~CS;
CHAR_SPI( 0x58);
CHAR_SPI (ADDRESS>>24); CHAR_SPI (ADDRESS>>16);
CHAR_SPI (ADDRESS>>8); CHAR_SPI (ADDRESS>>0);
CHAR_SPI( 0xFF);
.............
the code works fine for smaller addresses but when the address value exceeds 65535 it 'rolls over'.
I mean if I define
SECTOR = 160 then the address will be calculated as
ADDRESS = SECTOR*512 = 16384 !!
which should be wrong (correct value should be 81920) because I have defined ADDRESS as 'unsigned long' and that should be 32 bits. But why is it acting as 16 bits ?
I am using WINAVR-20050214 and AVR Studio 4.12 to compile my program.I am not using the latest version because with that AVR Studio wont simulate the code with it.
I tried to solve the problem by defining ADDRESS as uint32_t but that was no good either.
I even compiled the code with Imagecraft C compiler ICC AVR but still I had the same problem.
Can anyone please identify the problem over here.How can I (actually) define ADDRESS as a 32 bit number?