[En-Nut-Discussion] TWI Initialisation
Peter Sodermanns
peter.sodermanns at aixcon.de
Tue Feb 7 10:31:04 CET 2006
Hi group,
I'm trying to get TWI working on an Ethernut 2.1B but till now with no
success.
Initialisation of TWI seems to fail, I never get any signal on Port
D0/D1 (=SCL/SDA).
Hardware malfunction is unlikely, I tried 2 different Ethernuts, each
with just 1k5 pull up resistors on D0/D1.
My program is stripped down to the minimum and uses only twif.c:
#include <stdio.h>
#include <io.h>
#include <sys/version.h>
#include <sys/event.h>
#include <sys/timer.h>
#include <sys/heap.h>
#include <dev/debug.h>
#include <dev/twif.h>
int main(void)
{
u_long baud0 = 19200;
u_long TWI_speed;
int result = 0;
NutRegisterDevice(&devDebug0, 0, 0);
freopen("uart0", "w", stdout);
_ioctl(_fileno(stdout), UART_SETSPEED, &baud0);
NutSleep(200);
printf_P(PSTR("\n\n\n"));
printf_P(PSTR("Nut/OS: %s\n"), NutVersionString());
for (;;) {
printf_P(PSTR(" TWBR = %d\n"), TWBR);
printf_P(PSTR(" TWCR = %d\n"), TWCR);
printf_P(PSTR(" TWDR = %d\n"), TWDR);
printf_P(PSTR(" TWAR = %d\n"), TWAR);
printf_P(PSTR(" TWSR = %d\n"), TWSR);
result = TwInit(1);
printf_P(PSTR("TwInit MasterError = %d, result = %d\n"),
TwMasterError(), result);
printf_P(PSTR(" TWBR = %d\n"), TWBR);
printf_P(PSTR(" TWCR = %d\n"), TWCR);
printf_P(PSTR(" TWDR = %d\n"), TWDR);
printf_P(PSTR(" TWAR = %d\n"), TWAR);
printf_P(PSTR(" TWSR = %d\n"), TWSR);
TWI_speed = 10000;
result = TwIOCtl(TWI_SETSPEED, &TWI_speed);
printf_P(PSTR("TWI_SETSPEED MasterError = %d, result = %d\n"),
TwMasterError(), result);
printf_P(PSTR(" TWBR = %d\n"), TWBR);
printf_P(PSTR(" TWCR = %d\n"), TWCR);
printf_P(PSTR(" TWDR = %d\n"), TWDR);
printf_P(PSTR(" TWAR = %d\n"), TWAR);
printf_P(PSTR(" TWSR = %d\n"), TWSR);
while(1);
}
}
The resulting debug output is:
Nut/OS: 3.9.7.1
TWBR = 0
TWCR = 0
TWDR = 255
TWAR = 254
TWSR = 248
TwInit MasterError = 0, result = 0
TWBR = 191
TWCR = 5
TWDR = 255
TWAR = 3
TWSR = 250
TWI_SETSPEED MasterError = 0, result = 0
TWBR = 182
TWCR = 5
TWDR = 255
TWAR = 3
TWSR = 249
Problem:
TWINT in register TWCR is not set,
interrupt routine is never executed,
no signals at output pins.
Any ideas what the cause could be?
Many Thanks,
Peter
More information about the En-Nut-Discussion
mailing list