Hi,
refrence to the problem.....
I compiled the following code on just a regular GNU gcc compiler... (for my
pentium machine target, not the msp430)
see the output below:
union nibble_t {
struct nibbles {
unsigned nibble1:4;
unsigned nibble2:4;
unsigned nibble3:4;
unsigned nibble4:4;
};
unsigned char buffb[2];
unsigned buff;
};
int main(void)
{
int i;
union nibble_t nibble;
nibble.buffb[0]=0x12;
nibble.buffb[1]=0x34;
printf("\n2 bytes\n");
printf("nibble1 %x \n",nibble.nibble1);
printf("nibble2 %x \n",nibble.nibble2);
printf("nibble3 %x \n",nibble.nibble3);
printf("nibble4 %x \n",nibble.nibble4);
printf("\none word\n");
nibble.buff=0x1234;
printf("nibble1 %x \n",nibble.nibble1);
printf("nibble2 %x \n",nibble.nibble2);
printf("nibble3 %x \n",nibble.nibble3);
printf("nibble4 %x \n",nibble.nibble4);
return 0;
}
------------------------------- OUTPUT-----------------------
2 bytes
nibble1 2
nibble2 1
nibble3 4
nibble4 3
one word
nibble1 4
nibble2 3
nibble3 2
nibble4 1
the nibbles are swapped.... depending on access type.... how do we fix
this... that cuasing me problems in my structure.... write to it using a
one byte buff[i].. and then i want to access the low-nibble of the 5th
byte... but it gives me the high-nibble of the 5th byte... becuase of
swaping... i thought endian problems are only for accessing structures
larger than bytes.... any one have any ideas how can I get over this
problem...
thanks...
Abe
On November 19, 2003 12:27 pm, Garst R. Reese wrote:
> Sorry, they were in the original fwd.
> G.
>
> Dmitry wrote:
> > Oops...
> > where are bitfields?
> > ~d
> >
> > On Wednesday 19 November 2003 18:29, Garst R. Reese wrote:
> > > Dmitry wrote:
> > > > hm...
> > > > any code snippet?
> > > > ~d
> > >
> > > Sure, let me know if you need more.
> > > Thanks,
> > > Garst
> > >
> > > #ifdef _MMC_TEST
> > > int main(void)
> > > {
> > > unsigned int i;
> > > union reg16b_t reg16b;
> > > mcu_init();
> > > spi_init();
> > > lcd_init();
> > > clear_display();
> > > lcd_set_pos(0,0);
> > > get_register(MMC_SEND_CSD,®16b);
> > > print_register(®16b);
> > > print_response(0xEE);
> > > print_response(reg16b.csd.READ_BL_LEN);
> > > SPI_NONE;
> > > }
> > > #endif
> > >
> > >
> > > int get_register( unsigned char reg_cmd, union reg16b_t *reg16)
> > > {
> > > unsigned char arguments[4];
> > > unsigned char temp25;
> > > int i;
> > >
> > > arguments[0]=0x00;
> > > arguments[1]=0x00;
> > > arguments[2]=0x00;
> > > arguments[3]=0x00;
> > > temp25=mmc_sendcmd(reg_cmd,arguments);
> > > if(temp25)
> > > {
> > > SPI_NONE;
> > > SPI_LCD_EN;
> > > lcd_write_string("GETREG");
> > > print_response(temp25);
> > > BREAKPNT;
> > > return FALSE;
> > > }
> > > mmc_get_data((unsigned char*) reg16);
> > > return TRUE;
> > > }
> > >
> > >
> > > int mmc_get_data(unsigned char* data)
> > > {
> > > unsigned char temp25;
> > > int i ;
> > >
> > > while((temp25=mmc_get_response())==0); //if card is busy
> > > if(temp25!=0xFE)
> > > {
> > > BREAKPNT;
> > > return FALSE;
> > > }
> > >
> > > /*read the data*/
> > > for(i=0;i<16;i++)
> > > {
> > > data[i]=spi_read();
> > > }
> > >
> > > //CRC TOKENs
> > > spi_read();
> > > spi_read();
> > >
> > > return TRUE;
> > > }
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.net email is sponsored by: SF.net Giveback Program.
> > > Does SourceForge.net help you be more productive? Does it
> > > help you create better code? SHARE THE LOVE, and help us help
> > > YOU! Click Here: http://sourceforge.net/donate/
> > > _______________________________________________
> > > Mspgcc-users mailing list
> > > [email protected]
> > > https://lists.sourceforge.net/lists/listinfo/mspgcc-users
> >
> > --
> > /*****************************************************************
> > ("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
> > `6_ 6 ) `-. ( ).`-.__.`) State Polytechnical Univ.
> > (_Y_.)' ._ ) `._ `. ``-..-' Radio-Physics Departament
> > _..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
> > (il),-'' (li),' ((!.-' +7 (812) 5403923, 5585314
> > *****************************************************************/
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: SF.net Giveback Program.
> > Does SourceForge.net help you be more productive? Does it
> > help you create better code? SHARE THE LOVE, and help us help
> > YOU! Click Here: http://sourceforge.net/donate/
> > _______________________________________________
> > Mspgcc-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/mspgcc-users