Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. //write to the device wiper0
  2. void mcp41xxx_write0(uint8_t dat) {
  3. spi_write(MCP41XXX_P0 | MCP41XXX_CMD_WRITE); //send the command byte
  4. spi_write(dat); //send the data byte
  5. }
  6.  
  7. //write to the device wiper1
  8. void mcp41xxx_write1(uint8_t dat) {
  9. spi_write(MCP41XXX_P1 | MCP41XXX_CMD_WRITE); //send the command byte
  10. spi_write(dat); //send the data byte
  11. }
  12.  
  13. //first pot
  14. spi_select(MCP41XXX_CS1); //deselect cs1 -> idles high
  15. mcp41xxx_write0(i + i); //send the data
  16. spi_deselect(MCP41XXX_CS1); //select hte device
  17.  
  18. //second pot
  19. spi_select(MCP41XXX_CS2); //deselect cs1 -> idles high
  20. mcp41xxx_write0(i++); //send the data
  21. spi_deselect(MCP41XXX_CS2); //select the device
  22.  
  23. //send data on wiper0 of mcp4141
  24. void mcp41xx_write0(uint16_t dat) {
  25. dat = dat & 0x03ff; //10-bit data
  26. spi_write(MCP41XX_CMD_WRITE | MCP41XX_WIPER0 | (dat >> 8)); //write the msb
  27. spi_write(dat); //write the lsb
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement