error in variables handling

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

error in variables handling

510 Views
GMVS
Contributor III

hi

processor expert is making fun of me

i'm trying to attach an st m41t94 rtc to the mc9s08dz128mll using the spi2, but since i've got other stuff in the same bus, i'm using a 74hc595 sipo register for the slave selects.

i'm trying to make an echo access to the clock to try out the spi. this is part of my main

///

RTCwrite(0x02, 0x15);                      // (1)

  spiError= RTCread(0x02,time);

  a=*time;

  SIPO1Tx(a, TRUE, TRUE);

///

i'm writting, then reading, then placing what i read on a second sipo driving leds

the following lines are in another file

///

void RTCwrite(char RTCaddress, char data)                       // (2)

{

  RTCaddress = RTCaddress | 0x80; //turn on first bit to write         // (3)

  SPI2SIPOTx(0xFD, TRUE);

  SPI2M_SendChar(RTCaddress);

  SPI2M_SendChar(data);

  SPI2SIPOTx(0xFF, TRUE);

}

///

(1)  you can see how i'm sending a hex 2 and 15 to the rtc, i'm trying to access address register 2 which contains the minutes of the rtc and i'm telling it in bcd that rigth now its been 15 minutes.

(2) but when i run the debugger, RTCaddress has a 0x41 while data has the 0x15 i was sending. ??

(3) to tell the rtc that i'm writting i need to turn on the first bit of the address. so ideally i'll get 0x02 | 0x80 = 0x82. in this case i'd expect to have 0x41 | 0x80 = 0xc1, but i still get RTCaddress = 0x41. ????

given how this is no way working, i havent even tried the rest so i dont know if it works, at this point i dont care. all i care is why this stuff is not working??

next i tried this

///

RTCwrite(0x0002, 0x15);                      // (1)

  spiError= RTCread(0x02,time);

  a=*time;

  SIPO1Tx(a, TRUE, TRUE);

/////////////////

void RTCwrite(int RTCaddress, char data)                  

{

  RTCaddress = RTCaddress | 0x80; //turn on first bit to write            // (2)

  data = data | 0x80;                                                                  // (3)

  SPI2SIPOTx(0xFD, TRUE);

  SPI2M_SendChar(RTCaddress);

  SPI2M_SendChar(data);

  SPI2SIPOTx(0xFF, TRUE);

}

///

(1) this way the number pass nicely

(2) the operation works, i got a 0x0082

(3) but here this operation is ignored

so all i can conclude is processor experts (or code warrior) doesn't knows how to handdle chars

but i need the number as a char, not int, i could make a cast and truncate the int, but i dont think thats correct

also, are the following assumption correct?

byte = signed byte = sign + 7 bits

char = unsigned byte = 8 bits

int = signed double byte = sign + 15 bits

word = unsigned int = 16 bits

are short and long also available? and what would be their counterparts?

please help me out

1 Reply

361 Views
Petr_H
NXP Employee
NXP Employee

Hi,

regarding the types:

- char - can be signed or unsigned depending on the compiler, it can usually be configured in the compiler settings.

- byte - is defined by Processor Expert as unsigned char (8 bits)

- int - is signed, on HCS08 16 bits

- word - unsigned int, on HCS08 16 bits

I'm not sure what component do you use for the communication. If you use SynchroMaster, then the type of the sent/received data (ComponentName_TComData),  is a byte if the number of information bits ( Width property) is less than or equal to 8. If the number of information bits is greater than 8, the type of the user type ComponentName_TComData is a word.

I recommend to not use char and int in you r functions like RTCwrite, if you want to do bit-wise operations.

Please check the width and spi bus settings with the manual of the part and please post some sample project if you'll keep having troubles.

best regards

Petr Hradsky

Processor Expert Support Team