Tut mir leid, dass ich so lange nicht geantwortet habe, hatte soeben Prüfungen an der ETH.
Ich habe mal einen Versuch unternommen, einen Schaltplan zu zeichen, ich hoffe er ist genug klar, auch wenn mir bewusst ist, dass es eindeutig besser gehen würde
Das Program wird auf einem ArduinoMega ausgeführt und ist dementsprechend minimal anders als C
Code:#include <avr/io.h> uint8_t data[] = {0,0,0}; void SPI_init(void) { DDRB = ((1<<DDB2)|(1<<DDB1)|(1<<DDB0)); //spi pins on port b MOSI SCK,SS outputs SPCR = ((1<<SPE)|(1<<MSTR)|(1<<SPR1)); // SPI enable, Master, f/64 } uint8_t SPI_Transmit(uint8_t cData) { SPDR = cData; while(!(SPSR & (1<<SPIF))) ; return SPDR; } uint8_t SPI_receive() { SPCR &= ~(1 << SPE); //disable SPI DDRB |= ( 1 << DDB1); //set clock to output DDRB &= ~(1 << DDB2); //set MISO & MOSI to input DDRB &= ~(1 << DDB3); PORTB |= (1 << PB1); //generate 8 cycles on SCK delayMicroseconds(2); PORTB &= ~(1 << PB1); delayMicroseconds(2); PORTB |= (1 << PB1); delayMicroseconds(2); PORTB &= ~(1 << PB1); delayMicroseconds(2); PORTB |= (1 << PB1); delayMicroseconds(2); PORTB &= ~(1 << PB1); delayMicroseconds(2); PORTB |= (1 << PB1); delayMicroseconds(2); PORTB &= ~(1 << PB1); delayMicroseconds(2); PORTB |= (1 << PB1); delayMicroseconds(2); PORTB &= ~(1 << PB1); delayMicroseconds(2); PORTB |= (1 << PB1); delayMicroseconds(2); PORTB &= ~(1 << PB1); delayMicroseconds(2); PORTB |= (1 << PB1); delayMicroseconds(2); PORTB &= ~(1 << PB1); delayMicroseconds(2); PORTB |= (1 << PB1); delayMicroseconds(2); PORTB &= ~(1 << PB1); SPI_init(); //initialise SPI again return SPDR; //only formal (for later use) } void ADS1211_receive() { delayMicroseconds(10); SPI_Transmit(B00000100); //send INSR: write 1 Byte to Command Register Byte 3 (MSB) delayMicroseconds(5); SPI_Transmit(B01000010);//send Data: everything default except SDL = 1 delayMicroseconds(5); SPI_Transmit(B10000100);//send INSR: read 1 Byte (Command Register Byte 3 (MSB)) delayMicroseconds(5); data[0] = SPI_receive();//receive, expecting B01000010 } void setup() { Serial.begin(9600); Serial.write("starting up..."); //say hello DDRL &= ~( 1 << DDL1 ); //set DL1 to input pin for DRDY SPI_init(); //initialise SPI delay(1000); } void loop() { ADS1211_receive(); delayMicroseconds(20); delay(2); }







Zitieren

Lesezeichen