enhanced spi write function