I would need to control an MCP3208 with a Mikromedia for PIC32 board. On the forum I found only 8 bit PIC examples, but nothing that works with the Mikrobasic PRO for PIC32. Can anybody help me? This code doesn't work ...
Code: Select all
sub function ReadMCP2308(dim channel as byte) as word
dim tmp as word
dim txbyte as byte
Chip_Select = 0
if channel <= 3 then
txbyte = 6
end if
if ((channel > 3) and (channel < 8)) then
txbyte = 7
end if
SPI2_Write(txbyte)
channel = channel << 6
tmp = SPI2_Read(channel) and 0x0f
tmp = tmp << 8
tmp = tmp or SPI2_Read(0)
Chip_Select = 1
result = tmp
end sub
Thank you so much!