void main (void) { //Stop WDT WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //P3.4,5 = USCI_A0 TXD/RXD GPIO_setAsPeripheralModuleFunctionInputPin(__MSP430_BASEADDRESS_PORT3_R__, GPIO_PORT_P3, GPIO_PIN4 + GPIO_PIN5 ); //Initialize USCI UART module if ( STATUS_FAIL == UART_init(__MSP430_BASEADDRESS_USCI_A0__, UART_CLOCKSOURCE_SMCLK, UCS_getSMCLK(__MSP430_BASEADDRESS_UCS__), BAUD_RATE, UART_NO_PARITY, UART_LSB_FIRST, UART_ONE_STOP_BIT, UART_MODE, UART_OVERSAMPLING_BAUDRATE_GENERATION )){ return; } //Enable UART module for operation UART_enable(__MSP430_BASEADDRESS_USCI_A0__); //Enable Receive Interrupt UART_enableInterrupt(__MSP430_BASEADDRESS_USCI_A0__, UART_RECEIVE_INTERRUPT); //Enter LPM3, interrupts enabled __bis_SR_register(LPM3_bits + GIE); __no_operation(); }
int main() { initUART(); UART_enable(); UART_puts("\r\nSTARTING...\r\n"); PSX_init(); _delay_ms(1000); UART_puts("\r\nENTERING MAIN...\r\n"); while(1) { _delay_ms(50); PSX_get_button_state(); UART_puth(PSX_get_button_pressure(BUTTON_PRESSURE_R2)); UART_puts(" "); if(PSX_button_pressed(BUTTON_SQUARE)) { PSX_set_pressure_mode(CMD_PRESSURE_OFF); } if(PSX_button_pressed(BUTTON_TRIANGLE)) { PSX_set_pressure_mode(CMD_PRESSURE_ON); } if(PSX_button_pressed(BUTTON_R1)) PSX_set_input_mode(CMD_SET_ANALOG, CMD_LOCK_OFF); if(PSX_button_pressed(BUTTON_L1)) PSX_set_input_mode(CMD_SET_DIGITAL, CMD_LOCK_OFF); } return 0; }
MB_ErrorTypeDef sendFrame(uint16_t pduLength) { MB_ErrorTypeDef error = MB_ERROR_OK; uint16_t crc16; if (rxState == RX_STATE_IDLE) { pSndFrameCur = mbBuffer; sndFrameCount = MB_ADDR_LENGTH + pduLength; if (sndFrameCount <= MB_SIZE_MAX) { crc16 = getCrc16(pSndFrameCur, sndFrameCount); *(pSndFrameCur + sndFrameCount++) = (uint8_t)(crc16 & 0xFF); *(pSndFrameCur + sndFrameCount++) = (uint8_t)(crc16 >> 8); txState = TX_STATE_TMIT; UART_enable(false, true); }
MB_ErrorTypeDef MB_stop() { MB_ErrorTypeDef error = MB_ERROR_OK; if (mbState == MB_STATE_ENABLED) { mbState = MB_STATE_DISABLED; rxState = RX_STATE_IDLE; Timer_stop(); UART_enable(false, false); error = MB_ERROR_OK; } else { error = MB_ERROR_ILLSTATE; } return error; }
MB_ErrorTypeDef MB_start() { MB_ErrorTypeDef error = MB_ERROR_OK; if (mbState == MB_STATE_DISABLED) { mbState = MB_STATE_ENABLED; mbEvent = MB_EVENT_NONE; rxState = RX_STATE_INIT; txState = TX_STATE_IDLE; timerStart((uint16_t)(7 * tChar / 2), MB_t35Expired_cb); UART_enable(true, false); error = MB_ERROR_OK; } else { error = MB_ERROR_ILLSTATE; } return error; }
void MB_byte_sent_cb() { if (rxState != RX_STATE_IDLE) { //Line is busy return; } switch (txState) { case TX_STATE_IDLE: //Should not be called in normal operation break; case TX_STATE_TMIT: //Transmit next byte if (sndFrameCount) { //There is next byte UART_putByte(*pSndFrameCur); sndFrameCount--; pSndFrameCur++; } else { //Last byte transmitted just mbEvent = MB_EVENT_SENT; UART_enable(true, false); txState = TX_STATE_IDLE; } } }