Hi, I'm working with your SPI device driver but for the MCP4822 component, and it's not working.
There isn't any compiler or run-time errors, but it seems that the MCP4822 doesn't receive data.
This is the edited code of the driver:
`static rtems_libi2c_tfr_mode_t tfr_mode = {
.baudrate = 20000000,
.bits_per_char = 8,
.lsb_first = FALSE,
.clock_inv = TRUE,
.clock_phs = FALSE
};
static rtems_status_code spi_mcp4822_write(
rtems_device_major_number major,
rtems_device_minor_number minor,
void *arg
) {
rtems_status_code sc = RTEMS_SUCCESSFUL;
rtems_libio_rw_args_t *rwargs = arg;
int cnt = rwargs -> count;
unsigned char *buf = (unsigned char *) rwargs -> buffer;
/*send start*/
sc = rtems_libi2c_send_start(minor);
if(sc<0){
printf("send start error \n");
fflush(stdout);
return sc;
}else{
printf("start sended \n");
fflush(stdout);
}
/* ioctl*/
sc = rtems_libi2c_ioctl(minor, RTEMS_LIBI2C_IOCTL_SET_TFRMODE, &tfr_mode);
if ( sc != RTEMS_SUCCESSFUL ) {
printf("ioctl error \n");
fflush(stdout);
return sc;
}else{
printf("ioctl setted \n");
fflush(stdout);
}
/*send addr*/
sc = rtems_libi2c_send_addr(minor, FALSE);
if ( sc != RTEMS_SUCCESSFUL ) {
printf("send address error \n");
fflush(stdout);
return sc;
}else{
printf("address sended \n");
fflush(stdout);
}
/*write bytes*/
int data_sent_cnt = rtems_libi2c_write_bytes(minor, buf, cnt);
if (data_sent_cnt < 0) {
printf("write bytes error \n");
fflush(stdout);
return RTEMS_IO_ERROR;
}else{
printf("wrote %d bytes \n", data_sent_cnt);
fflush(stdout);
}
/*send stop*/
sc = rtems_libi2c_send_stop(minor);
if ( sc != RTEMS_SUCCESSFUL ) {
printf("send stop error \n");
fflush(stdout);
return sc;
}else{
printf("stop sended \n");
fflush(stdout);
}
return RTEMS_SUCCESSFUL;
}
/*read not used, data cannot be read from mcp4822 */
static rtems_status_code spi_mcp4822_read(
rtems_device_major_number major,
rtems_device_minor_number minor,
void *arg
) {
rtems_status_code sc = RTEMS_SUCCESSFUL;
return sc;
};
...`
rtems_status_code spi_mcp4822_read is empty because the MCP4822 can't be read.
I read the issue about the I2C device driver, and I understand that the libi2c is deprecated