Skip to content

Commit

Permalink
Fix reading pin mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mdclyburn committed Jul 10, 2019
1 parent 41eace0 commit 3256072
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/usci-spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace mardev::msp430::usci::spi
*ctl1 |= usci::UCSWRST;

const uint8_t pin_clock = SCLK[(uint8_t) module],
pin_mosi = SCLK[(uint8_t) module],
pin_miso = SCLK[(uint8_t) module];
pin_mosi = MOSI[(uint8_t) module],
pin_miso = MISO[(uint8_t) module];

// Configure pins.
dio::set_pin_mode(pin_clock, dio::pin_mode::output, dio::Function::Secondary);
Expand All @@ -37,14 +37,13 @@ namespace mardev::msp430::usci::spi

*ctl1 |= (uint8_t) clock_source;

const uint8_t settings = (uint8_t) clock_phase
*ctl0 = (uint8_t) clock_phase
| (uint8_t) clock_polarity
| (uint8_t) first_bit
| (uint8_t) character_length
// | (uint8_t) character_length // <- something about this sets the wrong bits
| (uint8_t) UCMST::Master // Assume master mode
| (uint8_t) spi_mode
| 1; // Synchronous mode enable
*ctl0 = settings;

*ctl1 &= ~usci::UCSWRST;

Expand All @@ -56,15 +55,15 @@ namespace mardev::msp430::usci::spi
{
// Wait for the buffer to be ready.
const uint8_t tx_flag = usci::TXIFG[(uint8_t) module];
while(*interrupt::registers::IFG2 & tx_flag);
while(!(*interrupt::registers::IFG2 & tx_flag));

// Write data out.
volatile uint8_t* const tx_buffer = usci::registers::TXBUF[(uint8_t) module];
*tx_buffer = data;

// Wait for data to be ready.
const uint8_t rx_flag = usci::RXIFG[(uint8_t) module];
while(*interrupt::registers::IFG2 & rx_flag);
while(!(*interrupt::registers::IFG2 & rx_flag));
volatile const uint8_t* const rx_buffer = usci::registers::RXBUF[(uint8_t) module];
return *rx_buffer;
}
Expand Down

0 comments on commit 3256072

Please sign in to comment.