heise online · c't · iX · Technology Review · Telepolis · mobil · Security · Netze · heise open · heise resale · Autos · c't-TV · Jobs · Kiosk
Zum Inhalt
c't

c't Projekte - c't-Bot und c't-Sim - Mailinglisten

c't-Bot und c't-Sim


[Voriger (Datum)] [Nächster (Datum)] [Voriger (Thread)] [Nächster (Thread)]
[Nach Datum][Nach Thread]

RE: [ct-bot] Problem mit Pointern

Absender: Timo Sandmann
Datum: Sa, 01.04.2006 23:05:38
In-reply-to: <BCF016D5ED5AC34FBB655D109519ABCF083DFC@xxxxxxxxxxxxxxxxxxxx>


Hallo Carsten,

ich habe leider nicht genug Zeit um den Code komplett nachvollziehen zu
können, aber du definierst in "Send_to_TWI()" die Variable "j" als "unsigned
char", schreibst dort "data_pack[i].size" rein und dekrementierst "j" in
jedem Schleifendurchlauf. Wenn jetzt "Get_byte(unsigned char *rx_ptr, char
last_byte)" aufgerufen wird, übergibst du den Wert von "j" (UNSIGNED char)
in die Variable "last_byte" (CHAR). Aber was macht der C-Compiler daraus,
wenn du einen unsigned char als char übergibst? Für die if-Abfrage auf
"last_byte" muss auf jeden Fall das Bitmuster mit dem von "j"
übereinstimmen, sonst führt eine 0 in "j" ja nicht zu FALSE in der Abfrage
von "last_byte". 

So, das fiel mir eben beim Durchlesen des Codes auf. 

Gruß Timo


> -----Original Message-----
> From: ct-bot-entwickler-bounces@xxxxxxxxxxxxxxxxx 
> [mailto:ct-bot-entwickler-bounces@xxxxxxxxxxxxxxxxx] On 
> Behalf Of Carsten Giesen
> Sent: Saturday, April 01, 2006 9:39 PM
> To: Entwicklung rund um den c't-bot
> Subject: AW: [ct-bot] Problem mit Pointern
> 
> Hallo Torsten,
> 
> Danke erstmal.
> 
> Ok, ich glaube da habe ich nicht gut genug gefragt.
> 
> Hier definire ich ein Dataset (so heißt das glaube ich)
> 
> void srf10_get_messure()
> {
> 	char temp0[1];
> 	char temp1;
> 	
> 	temp1 = 0;
> 	
> 	char state;
> 	tx_type tx_frame[3];
> 
> 	srf10_ping(SRF10_CENTIMETERS);
> 	
> 	state = SUCCESS;
> 
> 	tx_frame[0].slave_adr = SRF10_UNIT_0+W;
> 	tx_frame[0].size = 1;
> 	tx_frame[0].data_ptr = temp0;
> 	tx_frame[0].data_ptr[0] = 2;
> 
> 	tx_frame[1].slave_adr = SRF10_UNIT_0+R;
> 	tx_frame[1].size = 1;
> 	tx_frame[1].data_ptr = &temp1;
> 
> 	tx_frame[2].slave_adr = OWN_ADR;
> 
> 	state = Send_to_TWI(tx_frame);
> 
> 	Close_TWI();
> 
> 	srf10_m = temp1;
>        
> return;
> }
> 
> 
> Dieses wird an diese Routine übergeben:
> 
> unsigned char Send_to_TWI(tx_type *data_pack) {
> 	unsigned char state,i,j;
> 
> 	state = SUCCESS;
> 	
> 	for(i=0;(data_pack[i].slave_adr != OWN_ADR)&&(state == 
> SUCCESS);i++)
> 	{
> 		state = Send_start();				
> //Send START
> and repeated START
> 		if (state == SUCCESS)				
> 			state = Send_adr(data_pack[i].slave_adr);//Send
> slave address+W/R
> 		
> 		/*Dependent on the R/W in the slave address it 
> will receive or 
> 		transmitt data.*/
> 		if(!(data_pack[i].slave_adr & R))
> 		{
> 			/*If W, it will transmitt data and 
> loops until all data have been
> 			 shifted out*/
> 			for(j=0;((j<data_pack[i].size)&&(state ==
> SUCCESS));j++)
> 				state = 
> Send_byte(data_pack[i].data_ptr[j]);
> 		}	
> 		else
> //Else read from slave 
> 		{
> 			/*If R, it will receive data and loops 
> until all data have been
> 			 shifted in. When j == 0x00 this is the 
> last byte and a NACK 
> 			 will be sent to the slave to make it 
> stop transmitting */
> 			for(j=data_pack[i].size;((j>0)&&(state ==
> SUCCESS));j--)
> 				state = 
> Get_byte(data_pack[i].data_ptr++,j);
> 	
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 		}					
> 	}
>   	Send_stop();
> //Send STOP
>   	  
> 	return state;
> //Return SUCCESS if OK, 
> 	
> //else return TWSR
> } 
> 
> Und jetzt der Teil wo ich den Sensor auslesen will:
> 
> unsigned char Get_byte(unsigned char *rx_ptr,char last_byte) {
> 	Wait_TWI_int();
> //Wait for TWI interrupt flag set
> 
> 	/*When receiving the last byte from the slave it will 
> be sent a NACK to 
> 	make the slave stop transmitting, all bits before the 
> last will get 
> 	a ACK*/
> 	if(last_byte)
> //Not the last byte
> 		//Clear int flag and enable acknowledge to receive data.
> 		TWCR = ((1<<TWINT)+(1<<TWEA)+(1<<TWEN));
> 	else
> //Last byte
> 		/*Clear int flag to and do not enable 
> acknowledge to tell the slave 
> 		to stop transmitting*/
> 		TWCR = ((1<<TWINT)+(1<<TWEN)); 			
> 	Wait_TWI_int();
> //Wait for TWI interrupt flag set
> 
> 	*rx_ptr = TWDR;
> //Save received byte
> 
> 	/*If ACK has been transmitted or this was the last byte 
> and NACK has been
> 	sent -> return SUCCESS, else return TWSR*/	
>  	if(((TWSR == MRX_DATA_NACK)&&(last_byte == 0))||(TWSR ==
> MRX_DATA_ACK))
> 		return SUCCESS;	  
> 	return TWSR;
> }
> 
> Jetzt ist die ganze Kette zusammen
> 
> Zu Schull sollte in der Var "srf10_m" mein gemessener Wert stehen.
> Tut es aber nicht.
> 





Copyright © 2007 Heise Zeitschriften Verlag Kritik, Anregungen bitte an c't-WWW Datenschutzhinweis   Impressum