reading device ID from MCP251863 Click
Posted: 07 Dec 2022 03:25
Hello,
I am using MCP251863 Click and designed the SPI interface to read the device ID. I followed the spec to send the data to read (with 4-bit op code + 12-bit address), but receive all 0. The data on SIMO line is correct on the scope, CS and clock are also correct, but the SOMI line stays low. If a pull-up resistor is connected to SOMI line, then the line stays high.
I downloaded and looked at the library at this link https://libstock.mikroe.com/projects/vi ... 1863-click and find the example is not a complete project.
For example, the function spi_master_write_then_read() and spi_master_write() used in the below functions are not in the project source file. I understand they might be architecture dependent. I am wondering what to check next to find out the cause and solution.
Thanks for any advices!
Crane
err_t mcp251863_read_byte ( mcp251863_t *ctx, uint16_t address, uint8_t *data_out )
{
err_t error_flag;
spi_transmit_buffer[ 0 ] = ( uint8_t ) ( ( MCP251863_INS_READ << 4 ) + ( ( address >> 8 ) & 0xF ) );
spi_transmit_buffer[ 1 ] = ( uint8_t ) ( address & 0xFF );
spi_master_select_device( ctx->chip_select );
error_flag = spi_master_write_then_read( &ctx->spi, spi_transmit_buffer, 2, spi_receive_buffer, 1 );
spi_master_deselect_device( ctx->chip_select );
*data_out = spi_receive_buffer[ 0 ];
return error_flag;
}
err_t mcp251863_write_byte ( mcp251863_t *ctx, uint16_t address, uint8_t data_in )
{
err_t error_flag;
spi_transmit_buffer[ 0 ] = ( uint8_t ) ( ( MCP251863_INS_WRITE << 4 ) + ( ( address >> 8 ) & 0xF ) );
spi_transmit_buffer[ 1 ] = ( uint8_t ) ( address & 0xFF );
spi_transmit_buffer[ 2 ] = data_in;
spi_master_select_device( ctx->chip_select );
error_flag = spi_master_write( &ctx->spi, spi_transmit_buffer, 3 );
spi_master_deselect_device( ctx->chip_select );
return error_flag;
}
I am using MCP251863 Click and designed the SPI interface to read the device ID. I followed the spec to send the data to read (with 4-bit op code + 12-bit address), but receive all 0. The data on SIMO line is correct on the scope, CS and clock are also correct, but the SOMI line stays low. If a pull-up resistor is connected to SOMI line, then the line stays high.
I downloaded and looked at the library at this link https://libstock.mikroe.com/projects/vi ... 1863-click and find the example is not a complete project.
For example, the function spi_master_write_then_read() and spi_master_write() used in the below functions are not in the project source file. I understand they might be architecture dependent. I am wondering what to check next to find out the cause and solution.
Thanks for any advices!
Crane
err_t mcp251863_read_byte ( mcp251863_t *ctx, uint16_t address, uint8_t *data_out )
{
err_t error_flag;
spi_transmit_buffer[ 0 ] = ( uint8_t ) ( ( MCP251863_INS_READ << 4 ) + ( ( address >> 8 ) & 0xF ) );
spi_transmit_buffer[ 1 ] = ( uint8_t ) ( address & 0xFF );
spi_master_select_device( ctx->chip_select );
error_flag = spi_master_write_then_read( &ctx->spi, spi_transmit_buffer, 2, spi_receive_buffer, 1 );
spi_master_deselect_device( ctx->chip_select );
*data_out = spi_receive_buffer[ 0 ];
return error_flag;
}
err_t mcp251863_write_byte ( mcp251863_t *ctx, uint16_t address, uint8_t data_in )
{
err_t error_flag;
spi_transmit_buffer[ 0 ] = ( uint8_t ) ( ( MCP251863_INS_WRITE << 4 ) + ( ( address >> 8 ) & 0xF ) );
spi_transmit_buffer[ 1 ] = ( uint8_t ) ( address & 0xFF );
spi_transmit_buffer[ 2 ] = data_in;
spi_master_select_device( ctx->chip_select );
error_flag = spi_master_write( &ctx->spi, spi_transmit_buffer, 3 );
spi_master_deselect_device( ctx->chip_select );
return error_flag;
}