Hallo Kollegen,
hat nicht lange gedauert und …. da bin ich wieder mit ne Frage
Bin am „basteln“ am I2C Protokoll, STM32F103.
Funktionier erstmal zu 50% - das Adress-Byte wird gesendet und acknowledget.
Aber Data Bytes werden nicht gesendet.
Hat jemand `ne Idee woran es liegen kann?
Eistellungen für GPIO, Clock, ... sind gemacht.
+++++++++++++++++++++++++++++++++++
![Klicke auf die Grafik für eine größere Ansicht
Name: I2C.jpg
Hits: 5
Größe: 30,0 KB
ID: 34226](https://www.roboternetz.de/community/attachment.php?s=2a23e733b87ece909614b2e2832d0e38&attachmentid=34226&d=1561043573&thumb=1)
Der leerer Raum zwischen dem Address Byte und der STOP-Sequenz is durch die Schleife
for(k=0; k<350; k++){} verursacht.
+++++++++++++++++++++++++++++++++++
Code:
void I2C2Init(void) {
uI2C_CCR * pI2c2Ccr = (uI2C_CCR *)(I2C2_ADR + I2C_CCR_OFFSET);
uI2C_CCR I2C2Ccr;
uI2C_CR1 * pI2c2Cr1 = (uI2C_CR1 *)(I2C2_ADR + I2C_CR1_OFFSET);
uI2C_CR1 I2C2Cr1;
uI2C_CR2 * pI2c2Cr2 = (uI2C_CR2 *)(I2C2_ADR + I2C_CR2_OFFSET);
uI2C_CR2 I2C2Cr2;
uI2C_TRISE * pI2c2Trise = (uI2C_TRISE *)(I2C2_ADR + I2C_TRISE_OFFSET);
uI2C_TRISE I2C2Trise;
//RefMannual page 782-783
I2C2Cr2.All = 0;
I2C2Cr2.Bit.FREQ = 0x36; //36; //0x08
pI2c2Cr2->All = I2C2Cr2.All;
I2C2Ccr.All = 0;
I2C2Ccr.Bit.CCR = 0x00B4; //0x28; //Specification, page 70
pI2c2Ccr->All = I2C2Ccr.All;
I2C2Trise.All = 0;
I2C2Trise.Bit.TRISE = 0x12; //0x09;
pI2c2Trise->All = I2C2Trise.All;
I2C2Cr1.All = 0;
I2C2Cr1.Bit.ACK = 1; //1: Acknowledge returned after a byte is received
I2C2Cr1.Bit.PE = 1;
pI2c2Cr1->All = I2C2Cr1.All;
}
void I2cSend(void){
extern tTASTER TasterData[15];
uI2C_DR *pI2c2Dr = (uI2C_DR *)(I2C2_ADR + I2C_DR_OFFSET);
uI2C_DR I2C2Dr;
uI2C_CR1 *pI2c2Cr1 = (uI2C_CR1 *)(I2C2_ADR + I2C_CR1_OFFSET);
uI2C_CR1 I2C2Cr1;
uI2C_SR1 *pI2c2Sr1 = (uI2C_SR1 *)(I2C2_ADR + I2C_SR1_OFFSET);
uI2C_SR1 I2C2Sr1;
uI2C_SR2 *pI2c2Sr2 = (uI2C_SR2 *)(I2C2_ADR + I2C_SR2_OFFSET);
uI2C_SR2 I2C2Sr2;
unsigned char AddressI2c = 0;
unsigned char MessageI2c = 0;
unsigned char i = 0;
unsigned int k = 0;
for(i = 1; i<=14; i++){
AddressI2c = TasterData[i].AddressI2c; //daten aus Array bereitstellen
MessageI2c = TasterData[i].MessageI2c; //um Verzögerungen beim Senden zu vermeiden
while(0 != pI2c2Sr2->Bit.BUSY){ //wait for free bus
asm("NOP");
}
I2C2Dr.All = 0;
I2C2Cr1.All = pI2c2Cr1->All;
I2C2Cr1.Bit.START = 1;
pI2c2Cr1->All = I2C2Cr1.All;
while(1 != pI2c2Sr2->Bit.MSL){ //is Master Mode set?
asm("NOP");
}
I2C2Sr1.All = pI2c2Sr1->All; //SB=1, cleared by reading SR1 register ...
I2C2Dr.Bit.DR = AddressI2c; //...followed by writing DR register with Address.
pI2c2Dr->All = I2C2Dr.All; //write address in DR.
I2C2Sr1.All = pI2c2Sr1->All; //ADDR=1, cleared by reading SR1 register ...
I2C2Sr2.All = pI2c2Sr2->All; //...followed by reading SR2
while(0 != pI2c2Sr1->Bit.ADDR){ //Is the address send?
asm("NOP");
}
while(1 != pI2c2Sr1->Bit.TxE){ //TxE=1, shift register empty, data register empty
asm("NOP");
}
I2C2Dr.Bit.DR = MessageI2c;
pI2c2Dr->All = I2C2Dr.All; //write Data in DR.
// for(k=0; k<350; k++){}
I2C2Cr1.All = pI2c2Cr1->All;
I2C2Cr1.Bit.STOP = 1;
pI2c2Cr1->All = I2C2Cr1.All;
}
}
Lesezeichen