Projekte
mlade
zusammen_v4_1
TWIlib.h
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
zusammen_v4_1
compass.c
compass.h
fahren.c
fahren.h
globals.c
globals.h
gyro.c
gyro.h
interpret...befehle.c
interpret...befehle.h
main.c
TWIlib.c
TWIlib.h
uart.c
uart.h
ultraschall.c
ultraschall.h
werkzeuge.c
werkzeuge.h
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7433 private projects
378 public projects
16180353 lines compiled
58212 builds
NIBO
@
zusammen_v4_1/TWIlib.h [read only]
/* * TWIlib.h * * Created: 6/01/2014 10:38:42 PM * Author: Chris Herring */ #ifndef TWILIB_H_ #define TWILIB_H_ // TWI bit rate #define TWI_FREQ 100000 // Get TWI status #define TWI_STATUS (TWSR & 0xF8) //#### Folgende 2 geändert, war 20: M.Lade // Transmit buffer length #define TXMAXBUFLEN 10 // Receive buffer length #define RXMAXBUFLEN 10 // TWI Status Codes #define TWI_START_SENT 0x08 // Start sent #define TWI_REP_START_SENT 0x10 // Repeated Start sent // Master Transmitter Mode #define TWI_MT_SLAW_ACK 0x18 // SLA+W sent and ACK received #define TWI_MT_SLAW_NACK 0x20 // SLA+W sent and NACK received #define TWI_MT_DATA_ACK 0x28 // DATA sent and ACK received #define TWI_MT_DATA_NACK 0x30 // DATA sent and NACK received // Master Receiver Mode #define TWI_MR_SLAR_ACK 0x40 // SLA+R sent, ACK received #define TWI_MR_SLAR_NACK 0x48 // SLA+R sent, NACK received #define TWI_MR_DATA_ACK 0x50 // Data received, ACK returned #define TWI_MR_DATA_NACK 0x58 // Data received, NACK returned // Miscellaneous States #define TWI_LOST_ARBIT 0x38 // Arbitration has been lost #define TWI_NO_RELEVANT_INFO 0xF8 // No relevant information available #define TWI_ILLEGAL_START_STOP 0x00 // Illegal START or STOP condition has been detected #define TWI_SUCCESS 0xFF // Successful transfer, this state is impossible from TWSR as bit2 is 0 and read only #define TWISendStart() (TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN)|(1<<TWIE)) // Send the START signal, enable interrupts and TWI, clear TWINT flag to resume transfer. #define TWISendStop() (TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN)|(1<<TWIE)) // Send the STOP signal, enable interrupts and TWI, clear TWINT flag. #define TWISendTransmit() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)) // Used to resume a transfer, clear TWINT and ensure that TWI and interrupts are enabled. #define TWISendACK() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)|(1<<TWEA)) // FOR MR mode. Resume a transfer, ensure that TWI and interrupts are enabled and //respond with an ACK if the device is addressed as a slave or after it receives a byte. #define TWISendNACK() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)) // FOR MR mode. Resume a transfer, ensure that TWI and interrupts are enabled // but DO NOT respond with an ACK if the device is addressed as a slave or after it receives a byte. // Global transmit buffer extern uint8_t TWITransmitBuffer[TXMAXBUFLEN]; // Global receive buffer extern volatile uint8_t TWIReceiveBuffer[RXMAXBUFLEN]; // Buffer indexes extern volatile uint8_t TXBuffIndex; // Index of the transmit buffer. Is volatile, can change at any time. extern uint8_t RXBuffIndex; // Current index in the receive buffer // Buffer lengths extern uint8_t TXBuffLen; // The total length of the transmit buffer extern uint8_t RXBuffLen; // The total number of bytes to read (should be less than RXMAXBUFFLEN) //Eigene #define DELAY 500 // Damit die TWI sauber funktioniert. War: 250 #endif typedef enum { Ready, Initializing, RepeatedStartSent, MasterTransmitter, MasterReceiver, SlaceTransmitter, SlaveReciever } TWIMode; typedef struct TWIInfoStruct{ TWIMode mode; uint8_t errorCode; uint8_t repStart; }TWIInfoStruct; extern TWIInfoStruct TWIInfo; // Function declarations uint8_t TWITransmitData(void *const TXdata, uint8_t dataLen, uint8_t repStart); void TWIInit(void); uint8_t TWIReadData(uint8_t TWIaddr, uint8_t bytesToRead, uint8_t repStart); uint8_t isTWIReady(void); //Eigene extern uint8_t idx; extern uint8_t len; extern uint8_t data[TXMAXBUFLEN];
Compiler results:
Werbung
Online
deloresgoodin345909
gabrielstallcup
warrenhinder6456