void can_w_bit(uint8_t addr, uint8_t mask, uint8_t val) { CAN_CS_LOW; SPI_transmitData(MCP2515_SPI_BITMOD); SPI_transmitData(addr); SPI_transmitData(mask); SPI_transmitData(val); CAN_CS_HIGH; }
void can_w_txbuf(uint8_t bufid, void *buf, uint8_t len) { uint16_t i; uint8_t *sbuf = (uint8_t *)buf; CAN_CS_LOW; SPI_transmitData(MCP2515_SPI_LOAD_TXBUF | (bufid & 0x07)); for (i=0; i < len; i++) { SPI_transmitData(sbuf[i]); } CAN_CS_HIGH; }
void can_w_reg(uint8_t addr, void *buf, uint8_t len) { uint16_t i; uint8_t *sbuf = (uint8_t *)buf; CAN_CS_LOW; SPI_transmitData(MCP2515_SPI_WRITE); SPI_transmitData(addr); for (i=0; i < len; i++) { spi_transfer(sbuf[i]); } CAN_CS_HIGH; }
__interrupt void USCI_A0_ISR (void) { switch (__even_in_range(UCA0IV,4)){ //Vector 2 - RXIFG case 2: //USCI_A0 TX buffer ready? while (!SPI_getInterruptStatus(__MSP430_BASEADDRESS_USCI_A0__, SPI_TRANSMIT_INTERRUPT )) ; //Transmit data to master SPI_transmitData(__MSP430_BASEADDRESS_USCI_A0__, transmitData ); //Receive data from master receiveData = SPI_receiveData(__MSP430_BASEADDRESS_USCI_A0__); //Increment data to be transmitted transmitData++; break; default: break; } }
//***************************************************************************** // // Writes a data to the CFAF128128B-0145T. This function implements the basic SPI // interface to the LCD display. // //***************************************************************************** void HAL_LCD_writeData(uint8_t data) { /* USCI_B0 TX buffer ready? */ while (!EUSCI_B_SPI_getInterruptStatus(LCD_EUSCI_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)); SPI_transmitData(LCD_EUSCI_BASE,data); }
uint8_t can_spi_query(uint32_t moduleInstance) { uint8_t ret; CAN_CS_LOW; SPI_transmitData(moduleInstance, 0xFF); ret = SPI_receiveData(moduleInstance); CAN_CS_HIGH; return ret; }
//***************************************************************************** // // Writes a command to the CFAF128128B-0145T. This function implements the basic SPI // interface to the LCD display. // //***************************************************************************** void HAL_LCD_writeCommand(uint8_t command) { // Set to command mode GPIO_setOutputLowOnPin(LCD_DC_PORT, LCD_DC_PIN); /* USCI_B0 TX buffer ready? */ while (!EUSCI_B_SPI_getInterruptStatus(LCD_EUSCI_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)); SPI_transmitData(LCD_EUSCI_BASE,command); // Set back to data mode GPIO_setOutputHighOnPin(LCD_DC_PORT, LCD_DC_PIN); }
void can_spi_command(uint32_t moduleInstance, uint8_t cmd) { CAN_CS_LOW; SPI_transmitData(moduleInstance, cmd); CAN_CS_HIGH; }